Reputation: 1595
How can I make a MySQL query asking for all the string fields in a column that have a particular length?
Thanks!
Upvotes: 37
Views: 56479
Reputation: 723388
Use LENGTH()
for checking length in bytes:
SELECT str FROM sometable WHERE LENGTH(str) = 5;
Or CHAR_LENGTH()
for checking length in number of characters (useful for multi-byte strings):
SELECT str FROM sometable WHERE CHAR_LENGTH(str) = 5;
Upvotes: 66