37

How can I make a MySQL query asking for all the string fields in a column that have a particular length?

Thanks!

2 Answers 2

66

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;
Sign up to request clarification or add additional context in comments.

Comments

6
select * 
from myTable 
where length(myColumn) = 5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.