Reputation: 1782
I want to get a all the cars that end with a, c, d or f
I can get a list of cars ending with a doing this:
select model
from cars
where model like "a%";
But I want a list of the models ending not only with a, but also with the other chars above:
I have tried doing this (which doesn't return correct list):
select model
from cars
where model like "%a"
or model like "%c"
or model like "%d"
or model like "%f";
This is also a very ugly attempt/solution. Imagine if I needed more models.
I am using mysql
Thanks for any help
Upvotes: 0
Views: 107
Reputation: 284
Use regular expression to query $ means the end of String and ^ means the beginning
select model
from cars
where model REGEXP "(a|c|d|f)$";
If you wanted those characters in the beginning then you could have written:
select model
from cars
where model REGEXP "^(a|c|d|f)";
Upvotes: 1
Reputation: 2312
select model
from cars
where substring(model, -1) IN ('a','c','d','f')
Upvotes: 1