[ACCEPTED]-MySQL - Fetch rows where a field value is less than 5 chars-sql
Accepted answer
For MySQL you would use the LENGTH() function 1 ie.
select * from users where length(zip_code) < 5
Refer to the docs at http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_length for more information.
If you are searching for bad zip codes then 7 char_length(zip_code) < 5 is a start, but it 6 will still pass invalid ZIP codes.
use SELECT 5 * from users where char_length(zip_code) < 5 4 OR zip_code NOT REGEXP '^([0-9]{5})$'
The 3 regexp part basically searches for zip_codes 2 where the first 5 characters are not numbers 1 between 0-9
Have Fun
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.