Click to See Complete Forum and Search --> : Selecting only the first 50 characters of a certain column with mysql.


HellgY
02-04-2006, 11:29 AM
I know that there is a special artibute for this, But i can't seem to remember what it is...

chazzy
02-04-2006, 11:38 AM
use the substring function:


SELECT SUBSTRING(column,0,50) FROM your_table;


http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

HellgY
02-04-2006, 03:05 PM
Thanks Chazz!!!

chazzy
02-04-2006, 05:00 PM
by the way, i have to say i am very happy to see that your first idea was to use SQL.

decibel
10-07-2006, 06:20 PM
is it possible to alias a column and use SUBSTR?

like this:

SELECT SUBSTRING(column,0,50) as columnSummary FROM your_table;

chazzy
10-08-2006, 08:11 PM
of course it is.

decibel
10-08-2006, 08:13 PM
I tried it just like that, and it didn't seem to work, is my syntax wrong, or do i need to review my php?

chazzy
10-08-2006, 08:15 PM
maybe you should post some code.

decibel
10-08-2006, 08:17 PM
well i have already found a work around for this, and because i am on a tight schedule for work, i'll have to move on for now. I appreciate the help, next time i need to use the SUBSTRING function, I will try your suggestion, and If i continue having problems, I will return here and post the code.

Thanks again chazzy,
db.

chazzy
10-08-2006, 08:21 PM
ok, well most likely either the database version/vendor you use doesn't support substring (at least not that function name) or you have another error in your code.