John Himmelman John Himmelman - 1 year ago 61
MySQL Question

MySQL - Fetch rows where a field value is less than 5 chars

I need to fetch all the rows where the 'zip' field is less than 5 characters. How can I achieve this using only SQL? I google'd first, but only found info on CHAR_LENGTH().

ie, psudeo code: SELECT * FROM users WHERE STRLEN(zip_code) < 5


Answer Source

For MySQL you would use the LENGTH() function ie.

select * from users where length(zip_code) < 5

Refer to the docs at for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download