Reputation: 1
select * from airports
where field_name
like %A% and field_name like %B% and field_name like %C% and field_name like %D%
and field_name like %E% and field_name like %F% and field_name like %G%
and field_name like %H% and field_name like %I% and field_name like %J%
and field_name like %K% and field_name like %L% and field_name like %M%
and field_name like %N% and field_name like %O% and field_name like %P%
and field_name like %Q% and field_name like %R% and field_name like %S%
and field_name like %T% and field_name like %V% and field_name like %U%
and field_name like %W% and field_name like %Y% and field_name like %Z%
Upvotes: 0
Views: 40
Reputation: 173582
You could make use of LOCATE()
to query the first letter against a string comprising the letters you're interested in:
WHERE LOCATE(LEFT(field_name, 1), 'ABCDEFGHIJKLMNOPQRSTUVWYZ')
That will return results where name
starts with any of those alphabets (which is practically all possible letters safe for X).
Or, using a regular expression:
WHERE field_name REGEXP '^[A-Z]'
Change the character set where needed.
Upvotes: 1
Reputation: 172458
You are missing the where
keyword for your column and instead of and
use or
condition.
Something like this:
select * from airports where
column_name like 'A%' or column_name like 'B%' ......
Also if you want to check that the column name starts with a particular alphabet then the wildcard character should be last only like
column_name like 'A%'
or better use REGEX:
WHERE column_name REGEXP '^[A-Z]'
Upvotes: 1