How do I write a sql query to select names that can contain any vowel?

I am trying to query a database with about 2000 records. I want to select records where names can contain any vowel.

I tried using the following query, but it gives me those entries that contain all the characters specified in that order.

select * from myTable where name like '%a%e%i%';

      

How to change the above query to select those records with names that can contain at least one of the vowels.

+3


source to share


5 answers


Hope this helps you ...



 SELECT * FROM myTable WHERE name REGEXP 'a|e';
 or.....
 SELECT * FROM myTable WHERE name REGEXP 'a|e|i';

      

+1


source


Try this for SQL Server:



SELECT * FROM myTable WHERE name LIKE '%[AEIOU]%';

      

+2


source


In SQL Server, you must:

where name like '%[aeiou]%';

      

In MySQL, you would do something similar with a regex.

+1


source


Use OR

as follows.

This will work for both SQL Server and MySql.

select * from myTable where name like '%a%' OR name like '%e%' OR name like '%i%';

      

+1


source


Use LIKE

and OR

.

Query

select * from myTable
where name like '%a%'
or name like '%e%'
or name like '%i%'
or name like '%o%'
or name like '%u%'

      

0


source







All Articles