Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:20:25+00:00 2026-05-28T06:20:25+00:00

Here is my example. When I run this query: SELECT SUBSTRING(‘Lorem ipsum dolor sit

  • 0

Here is my example. When I run this query:

SELECT SUBSTRING('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae odio tellus, sit amet facilisis neque. Cras sapien nulla, suscipit non imperdiet ac, aliquet vitae lectus. Nulla a varius dolor. Nunc convallis, augue et fermentum volutpat, lectus urna sagittis risus, vel iaculis diam est convallis lectus. Suspendisse potenti. Morbi malesuada tristique varius.', 1, 300)

I get the first 300 chars of the sentence. That is good. Except that I want it to end where the last dot (.) is in the result.

So the query result is this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae odio tellus, sit amet facilisis neque. Cras sapien nulla, suscipit non imperdiet ac, aliquet vitae lectus. Nulla a varius dolor. Nunc convallis, augue et fermentum volutpat, lectus urna sagittis risus, vel iaculis diam est convalli

But I want it to be this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae odio tellus, sit amet facilisis neque. Cras sapien nulla, suscipit non imperdiet ac, aliquet vitae lectus. Nulla a varius dolor.

Can I do that with a MySQL query, and how?

Tnx


UPDATE 1,
This is what I had so far:

SET @longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae odio tellus, sit amet facilisis neque. Cras sapien nulla, suscipit non imperdiet ac, aliquet vitae lectus. Nulla a varius dolor. Nunc convallis, augue et fermentum volutpat, lectus urna sagittis risus, vel iaculis diam est convallis lectus. Suspendisse potenti. Morbi malesuada tristique varius.';

SELECT SUBSTRING_INDEX(
    @longtext,
    SUBSTRING_INDEX(
        SUBSTRING(
            @longtext,
            1,
            300
        ),
        '.',
        -1
    )
    , 1
);

UPDATE 2,
Tnx @Ben

My solution is:

SET @longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae odio tellus, sit amet facilisis neque. Cras sapien nulla, suscipit non imperdiet ac, aliquet vitae lectus. Nulla a varius dolor. Nunc convallis, augue et fermentum volutpat, lectus urna sagittis risus, vel iaculis diam est convallis lectus. Suspendisse potenti. Morbi malesuada tristique varius.';

SELECT SUBSTRING(
    @longtext,
    1,
    300 - ifnull(
        LOCATE(
            '.',
            REVERSE(
                SUBSTRING(
                    @longtext,
                    1,
                    300
                )
            )
        ),
    1)
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:20:25+00:00Added an answer on May 28, 2026 at 6:20 am

    Okay, so I think I’ve got it; comments are unfortunately in reverse due to the nature of the thing…

    select substr('my_string', 1
                -- 300 - distance from the first '.' in the reversed string.
                 , 300 - ifnull(
                               -- Get the 1st position of the '.' in the
                               -- reversed string.
                                locate('.', reverse(substr('my_string',1,300))
                                      )
                              -- if it's null, i.e. doesn't exist, replace it with 1.
                               , 1)
                  )
    

    You can change the 300 as you wish.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The fictional example here. Suppose I designed a class named IODevice. This class already
This problem is not readily reproducible in a simple example here but was wondering
What does this do? I find the example here, but other than what it
Here's an example of the sort of query I would like to prevent from
Here's my current query: SELECT IFNULL(sum(open_for), 0) total, count(IF(open_for > 0, 1, null)) wins,
I found a great C++/ODBC example here ... The project I downloaded builds great
OK, probably best to give an example here of what I mean. Imagine a
I would like to translate or 301-redirect urls such as: www.domain.com/example.html to www.domain.com/example Here
(dd/MM/yyyy HH)+ - + (x.Hour+1).ToString(); So here is example what I got and what
Here is an example of what I've got going on: CREATE TABLE Parent (id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.