Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select rows from database by strlen

Is there a way to select database table rows where a given value is a certain length, for example, less than 5 chars long?

In PHP that would be strlen.

Is there anything similar in MySQL?

like image 621
santa Avatar asked Feb 19 '11 02:02

santa


People also ask

How do I query the length of a string in SQL?

Well, you can use the LEN() function to find the length of a String value in SQL Server, for example, LEN(emp_name) will give you the length of values stored in the column emp_name.

How do I find the length of a word in MySQL?

MySQL LENGTH() Function The LENGTH() function returns the length of a string (in bytes).


1 Answers

SELECT * FROM table_name WHERE CHAR_LENGTH(column_name) < 5 
like image 139
Derek Prior Avatar answered Oct 14 '22 00:10

Derek Prior