Reputation: 501
Structure:
table
c1 c2
1 test
1 test2
2 test
2 test3
3 test4
SQL:
SELECT c1 FROM table WHERE c2 in ("test3","test4")
What I want:
SELECT c1 FROM table WHERE c2 in ("%3","%st4")
How can I do this?
Upvotes: 0
Views: 266
Reputation: 17289
Here is my approach just to follow the logic you have in your question:
http://sqlfiddle.com/#!9/aca65e/2
SELECT *
FROM `table`
WHERE c2 REGEXP '.*3$|.*st4$';
But keep in mind that solution
SELECT c1 FROM table WHERE (c2 like "%3") or (c2 like "%st4")
provided by @splash58 could be much faster if c2
column is indexed.
Upvotes: 0