Retrieving only a portion of a record in a database

I have a database that contains several topics, each of which has a title and some description. On the cover page, I should display all the headings and several description lines for this topic. When a user clicks on one topic, he gets to a page where he can find a full description. Just like the stackoverflow site, where a brief description of the description of each question is displayed.

I was wondering if there is a way by which we can get such a brief description from the database directly or should the interface parse the extracted record and truncate it accordingly? Is there a way to directly request a short version of a record from a database. I use MySql as my database and php to display web pages.

+3
source share
6 answers

I would say that the answer is found in this post: SQL Server substring breaking words, not characters

You would not want to limit the length of the string, since then you can cut the word right in the middle. Instead, you want to set the maximum length, and then return to the place where there is a space.

Another option would be to run this once, and then update the field in the table in which the truncated text is stored. This way you can limit your extra SQL calls and still have a well-formatted summary text.

+2
source
SELECT SUBSTRING(`title`, 0, 100) FROM `topics`
+3
source

:

SELECT SUBSTRING_INDEX('your string', ' ', 10);

10 .

: SUBSTRING , @BiggsTRC

+2
  select LEFT (description, CHARINDEX(' ', description, 50) ) from topics

, , ... .

+1
source

Do you mean a piece of text from a text box?

how select left(LongTextField,200) from myTable

0
source

You can limit the value that you return with the same product: select the name, cast (description as varchar (300)) from the table

or you can save a less abrasive truncated description in the form of a small description or something else in the table (then make your interface so that you mark it and it cuts it for you ^^).

0
source

All Articles