views:

30

answers:

1

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")?

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
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
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
or try `left(description, 500)` or whatever number you need
ceteras
Okay, yeah. Those both work.
Azmisov