Reputation: 13
SELECT * FROM table1 WHERE tagName LIKE '%ABC%' OR tagName LIKE '%DEF%';
I want to limit the number of data I get from each like. Is possible?
Upvotes: 1
Views: 51
Reputation: 164069
You can do it with UNION ALL
, but you have to nest each one of the statements as a subquery so that LIMIT
can work, otherwise it's syntactically wrong:
SELECT * FROM (SELECT * FROM table1 WHERE tagName LIKE '%ABC%' LIMIT 10) t
UNION ALL
SELECT * FROM (SELECT * FROM table1 WHERE tagName LIKE '%DEF%' LIMIT 10) t
Note: LIMIT without ORDER BY is never a good idea.
Upvotes: 0
Reputation: 359
You could separate the queries by LIKE
and specify the limit
, finally UNION ALL
(SELECT * FROM table1 WHERE tagName LIKE '%ABC%' LIMIT 1)
UNION ALL
(SELECT * FROM table1 WHERE tagName LIKE '%DEF%' LIMIT 1);
Upvotes: 2