MySql find all rows where data contains less than four characters

How to write this sql-english query correctly:

"SELECT zip FROM tblContacts WHERE [the number of characters in zips is less than or equal to 4]."

Thank.

+3
source share
3 answers

Assuming what zipis the string:

WHERE CHAR_LENGTH(zip) <= 4

must work.

Edit : There was initially some confusion as to whether the desired comparison was <, <=or >, but now Q has been edited to clarify, so I edited my A accordingly.

+6
source
SELECT zip FROM tblContacts WHERE CHAR_LENGTH(zip) > 0
+1
source

I am sure there should be a better way, but ...:

SELECT zip FROM tblContacts WHERE zip LIKE '_' OR zip LIKE '__' OR zip LIKE '___' OR zip LIKE '____';
0
source

Source: https://habr.com/ru/post/1728777/


All Articles