mysql - Add dots if string has more than 10 words -


i want return preview of texts getting first 10 words.

concat(substring_index(q.value, ' ', 10), '...') preview 

this works great when string long. should not added when string shorter (because there nothing more).

is possible 100% mysql?

you can use case:

select (case when substring_index(q.value, ' ', 10) = q.value              q.value              else concat(substring_index(q.value, ' ', 10), '...')         end) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -