Union - Same table, excluding previous results MySQL
- by user82302124
I'm trying to write a query that will:
Run a query, give me (x) number of rows (limit 4)
If that query didn't give me the 4 I need, run a second query limit 4-(x) and exclude the ids from the first query
A third query that acts like the second
I have this:
(SELECT *, 1 as SORY_QUERY1 FROM xbamZ where state = 'Minnesota'
and industry = 'Miscellaneous' and id != '229' limit 4) UNION (SELECT
*, 2 FROM xbamZ where state = 'Minnesota' limit 2) UNION (SELECT *, 3 FROM xbamZ where industry = 'Miscellaneous' limit 1)
How (or is?) do I do that? Am I close? This query gives me duplicates