[ACCEPTED]-MySQL - Fetch rows where a field value is less than 5 chars-sql

Accepted answer
Score: 33

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.

Score: 2

You can use length

SELECT * FROM table WHERE LENGTH(myfield) < 5; 

Check this out for more info.

0

Score: 2

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

More Related questions