MYSQL:只拉最小字符长度的单词

时间:2010-04-04 22:21:17

标签: mysql select

如何从MYSQL中仅提取最多50个字符的单词?

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

3 个答案:

答案 0 :(得分:5)

尝试在WHERE约束中使用CHAR_LENGTH函数:

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

CHAR_LENGTH返回字符串中的字符数。 LENGTH返回字节数。如果您的单词可能包含多字节字符,则优先使用CHAR_LENGTH

答案 1 :(得分:0)

答案 2 :(得分:0)

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