Azmisov
Azmisov

Reputation: 7233

Limit characters for mysql_query(select) lookup

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

Upvotes: 2

Views: 3860

Answers (1)

Jagmag
Jagmag

Reputation: 10356

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.

Upvotes: 1

Related Questions