Reputation: 193
how can I pull only words with maximum 50 Characters from MYSQL?
$query = "SELECT * FROM example ORDER BY ID DESC LIMIT 200";
Upvotes: 0
Views: 2838
Reputation: 26120
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.
Upvotes: 6
Reputation: 8653
SELECT * FROM example WHERE LENGTH(column) <= 50 ORDER BY ID DESC LIMIT 200
Upvotes: 1
Reputation: 2524
Try the length() function http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
Upvotes: 0