tags:

views:

41

answers:

3

Hi, how can I pull only words with maximum 50 Characters from MYSQL?

$query = "SELECT * FROM example ORDER BY ID DESC LIMIT 200"; 
A: 

Try the length() function http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

rkulla
A: 
SELECT * FROM example WHERE LENGTH(column) <= 50 ORDER BY ID DESC LIMIT 200
Xorlev
If you're going to downrate for a perfectly correct answer, leave a comment.CHAR_LENGTH() may be multi-byte friendly, but LENGTH() works as well.
Xorlev
+2  A: 

Try using the CHAR_LENGTH function in a WHERE constraint:

SELECT * FROM example WHERE CHAR_LENGTH(word) <= 50 ORDER BY ID DESC LIMIT 200

CHAR_LENGTH returns the number of characters in the string. LENGTH returns the number of bytes. It is prefeable to use CHAR_LENGTH if your word could contain multi-byte characters.

Phil Ross
thank you for the great answer!! :)
elmaso