I need to select rows that have one treated row for one country and there exists one untreated row for the same country. For below table I would then return row with id = 1.
So first I need to check if there is a row with TREATED status, then I have to check if there is a row with UNTREATED status and the same country as the one with the TREATED status.
Table example 1
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
| 2 | DK | UNTREATED |
| 3 | SE | UNTREATED |
+----+--------+--------------+
Result of query
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
+----+--------+--------------+
If there does not exist an untreated row or the country is not the same then we should not return anything
Table example 2
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
| 2 | DK | UNTREATED |
| 3 | US | UNTREATED |
+----+--------+--------------+
Result of query (empty)
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
Here are a couple of other options:
I believe the first one, using a join, would probably perform the best.