Is there an efficient way to limit the number of characters for a mysql query lookup? So, if a text column field had 18000 characters, but I only need to query 500 characters, is there a way to mysql_query("select text_column
from random_table
limit_char_count 500")?
views:
30answers:
1
A:
How about using the SUBSTRING() function? Below example selects 4 characters starting from 1st position
SELECT SUBSTRING(text_column,1,4)
FROM random_table
WHERE something = something else
EDIT - edited based on - for all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.
InSane
2010-08-22 01:10:27
I tried this:$var = mysql_query("select substring('description',0,20) as 'wierd_thing','id','name' from 'fn' order by 'id'");but $var['wierd_thing'] is blank.
Azmisov
2010-08-22 02:03:02
My bad - For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1 - can u please try with 1, 20 instead? I think that might be the problem. I dont have mySQL to actually try it out
InSane
2010-08-22 02:16:59
or try `left(description, 500)` or whatever number you need
ceteras
2010-08-23 10:54:49
Okay, yeah. Those both work.
Azmisov
2010-08-23 17:46:37