I have following table:
+--------+-----------+--------+
| ID | Title | Stat |
+--------+-----------+--------+
| 1 | title a | 1 |
+--------+-----------+--------+
| 1 | title b | 0 |
+--------+-----------+--------+
| 2 | title c | 1 |
+--------+-----------+--------+
| 2 | title d | 1 |
+--------+-----------+--------+
| 3 | title e | 0 |
+--------+-----------+--------+
| 3 | title f | 1 |
+--------+-----------+--------+
| 3 | title g | 1 |
+--------+-----------+--------+
I need to construct a query, where as a result only those records would be included where ALL values in column Stat meet certain condition.
For above table, how to formulate a query that would basically mean: show me records for only those ID’s that have all the values in column Stat = 1 and would as a result produce following table?
+--------+-----------+--------+
| 2 | title c | 1 |
+--------+-----------+--------+
| 2 | title d | 1 |
+--------+-----------+--------+
Thanks.
Something like this?
Basically, the subquery computes the minimum stat per ID, whereas the outer query only selects the rows with the minimal stat equal to 1. If all rows need to satisfy a certain condition, insert a boolean expression in stead of Stat in the minimum.
Not sure if this is possible without a subquery.