mySQL question

Joined
Jul 25, 2004
Messages
389
Reaction score
5
Points
18
Location
Gaithersburg, MD
Your Mac's Specs
Mac Pro 2.6ghz Quad Xeon, 23" Cinema
I was wondering how to only get the first x number of characters in an SQL query. Like if you have a field called job_description and you want to only display the first 50 chars or so as a "preview." Do you think it would be easier to use a built-in PHP function to crop it or is there a way to do it with the select statement. I don't have any of my reference books handy so I can't look it up.
 
Joined
Jun 11, 2003
Messages
4,915
Reaction score
68
Points
48
Location
Mount Vernon, WA
Your Mac's Specs
MacBook Pro 2.6 GHz Core 2 Duo 4GB RAM OS 10.5.2
LEFT(str,len)
Returns the leftmost len characters from the string str.

mysql> SELECT LEFT('foobarbar', 5);
-> 'fooba'
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top