Here is the table-
+----+---------+--------+
| id | letters | status |
+----+---------+--------+
| 1 | A | 0 |
| 2 | B | 1 |
| 3 | C | 0 |
| 4 | D | 0 |
| 5 | E | 1 |
| 6 | F | 1 |
| 7 | G | 0 |
| 8 | H | 0 |
+----+---------+--------+
Its need to finds records with the conditions below-
- select letters with
LIMIT 3
ORDER
isRAND()
status true or false
both need to present but at-least a presents of letters withstatus TRUE
but not more then2
Desire results could be as-
+---------+--------+
| letters | status |
+---------+--------+
| B | 1 |
| E | 1 |
| H | 0 |
+---------+--------+
+---------+--------+
| letters | status |
+---------+--------+
| C | 0 |
| E | 1 |
| H | 0 |
+---------+--------+
But not as-
+---------+--------+
| letters | status |
+---------+--------+
| C | 0 |
| G | 0 |
| H | 0 |
+---------+--------+
+---------+--------+
| letters | status |
+---------+--------+
| B | 1 |
| E | 1 |
| F | 1 |
+---------+--------+
Anyone please help.