My table:
id | elite | pos
1 | 0 | 9
2 | 1 | 8
3 | 0 | 7
4 | 1 | 6
5 | 0 | 5
6 | 1 | 4
7 | 0 | 3
8 | 1 | 2
9 | 0 | 1
10 | 1 | 0
I have this simple query
SELECT id, elite FROM tbl LIMIT 0, 5 ORDER BY pos DESC
It will return the id 1 2 3 4 5. Over time, these values were to change. The result must have always a count of 5, however if on the result there are at least one id with an elite >= 1, the result must not contain any more id with an elite having the 1 value. So the result must not contain id having more than one elite >= 1.
Is this possible within a query?
You can use
UNIONto combine two queries, like so:It will give the results you need.
Check out Mysql reference for UNIONs