Jun
09
2005
0

MYSQL: Find a Range

Want to find users whose lastnames start with the letters between A and O?

SELECT * FROM users
WHERE SUBSTR(lastname, 1,1)
BETWEEN ‘A’ AND ‘O’;

Notice SUBSTR is 1 based… annoying!

Second observation, SUBSTR is a 4.1 alias for SUBSTRING so if you aren’t using 4.1+ you’ll want to use SUBSTRING rather than SUBSTR

Written by Aaron Wormus in: Cookbook, MySQL |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes