ID stone_free original_stone_id
------- | ---------- | -------------------
1 | 0 | 1
2 | 1 | 2
3 | 1 | 1
I would like to return rows from the table only if stone_free equals 0 and there is no corresponding original_stone_id in other rows for each row. So for example in the above example row 1 has stone_free as 0 and there is a corresponding original_stone_id in row 3, therefore the query shouldn’t return any rows.
In the example below row 1 has stone_free as 0 but there is no corresponding original_stone_id in the other row, therefore the query should return row 1.
ID stone_free original_stone_id
------- | ---------- | -------------------
1 | 0 | 1
2 | 1 | 2
A simple
LEFT JOINshould do it;Demo here.