elmaso
elmaso

Reputation: 193

MYSQL: Pull Only Words with Minimum Character length

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

Answers (3)

Phil Ross
Phil Ross

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

Xorlev
Xorlev

Reputation: 8653

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

Upvotes: 1

rkulla
rkulla

Reputation: 2524

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

Upvotes: 0

Related Questions