Skip to content
Advertisement

Replace multiple OR operators with a single IN or ANY operator

I would like to query a list of cities that end in vowels and I would like each city in the list to be distinct. The code noted below works fine but I would like to achieve the same thing using the IN or ANY operators.I have attached a picture of the description of the table I’m working with. Thank you!

SELECT DISTINCT City FROM Station
WHERE City LIKE '%a' 
OR City LIKE '%e'
OR City LIKE '%i'
OR City LIKE '%o'
OR City LIKE '%u';

Table description

Advertisement

Answer

Use regexp

select DISTINCT 
City   FROM Station 
WHERE  regexp_like(city,'[aeiou]$')
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement