MySQL - How to select data by string length

Viewed 344427
SELECT * FROM table ORDER BY string_length(column);

Is there a MySQL function to do this (of course instead of string_length)?

7 Answers

In my case I get data using mobile number length greater than 10 digits using the below query

SELECT * FROM table_name WHERE CHAR_LENGTH(mobile) > 10;

I used this sentences to filter

SELECT table.field1, table.field2 FROM table WHERE length(field) > 10;

you can change 10 for other number that you want to filter.

select * from *tablename* where 1 having length(*fieldname*)=*fieldlength*

Example if you want to select from customer the entry's with a name shorter then 2 chars.

select * from customer where 1 **having length(name)<2**
Related