I have to retrieve distinct entities from a column, all of which start with a vowel. The query looks like this :
Select DISTINCT column_name FROM table_name WHERE column_name LIKE '[aeiou]%';
It’s not giving compilation errors, but it’s not returning anything. Any ideas?
Advertisement
Answer
You can use regular expressions:
Select DISTINCT column_name FROM table_name WHERE column_name REGEXP '^[aeiou]';
LIKE
wildcard patterns do not support character classes, except in a couple of databases that extend the definitions of the LIKE
pattern.
Also, you might want:
WHERE column_name REGEXP '^[aeiouAEIOU]'
If you have a case-sensitive collation.