开发者

MYSQL: Pull Only Words with Minimum Character length

开发者_JAVA技巧

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

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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜