Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Display only 200 characters from total value

I have a MySQL table with a field named description, with a record like this:

Former cop Brian O'Conner partners with ex-con Dom Toretto on the opposite side of the law.Since Brian and Mia Toretto broke Dom out of custody, they've blown across many borders to elude authorities. Now backed into a corner in Rio de Janeiro, they must pull one last job in order to gain their freedom. As they assemble their elite team of top racers, the unlikely allies know their only shot of getting out for good means confronting the corrupt businessman who wants them dead. But he's not the only one on their tail. Hard-nosed federal agent Luke Hobbs never misses his target. When he is assigned to track down Dom and Brian, he and his strike team launch an all-out assault to capture them. But as his men tear through Brazil, Hobbs learns he can't separate the good guys from the bad.

How can I display first 200 characters of it? Like this:

Former cop Brian O'Conner partners with ex-con Dom Toretto on the opposite side of the law.Since Brian and Mia Toretto broke Dom out of custody, they've blown across many borders to elude authorities.

like image 357
SB24 Avatar asked Nov 04 '11 14:11

SB24


People also ask

How do I see the number of characters in MySQL?

MySQL CHAR_LENGTH() returns the length (how many characters are there) of a given string. The function simply counts the number characters and ignore whether the character(s) are single-byte or multi-byte.

What does VARCHAR 30 mean?

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters. The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255.

What is the use of <> in MySQL?

The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0.

Is there a Contains function in MySQL?

MySQL query string contains using INSTR INSTR(str, substr) function returns the index of the first occurrence of the substring passed in as parameters. Here str is the string passed in as the first argument, and substr is the substring passed in as the second argument.


2 Answers

SELECT LEFT(description, 200)
FROM yourtable

relevant docs here.

like image 197
Marc B Avatar answered Oct 10 '22 06:10

Marc B


Try this:

SELECT SUBSTR(description, 1, 200) 
FROM your_table

You can find docs here

like image 39
Marco Avatar answered Oct 10 '22 07:10

Marco