Select a Range of Letters Select a Range of Letters sql sql

Select a Range of Letters


Select the names from 'A' up to, but not including 'E':

select ID, Namefrom SampleTablewhere Name >= 'A' and Name < 'E'order by Name

As this is a plain comparison, it can use an index if you have one for that field.


Guffa's answer is probably the most efficient. To be complete, you could also use

LIKE '[a-d]%'

Depending on your database COLLATION, LIKE might be case sensitive or not.


select id, namefrom tablewhere LOWER(LEFT(name, 1)) between 'a' and 'd'order by name;

If you want to match multiple character then use

select id, name  from table where name >= 'Cr'    and (name < 'D' OR name like 'D%') order by name;