I need to delete record from ent table that does not exist in both column of ent_id or ent_id_val in table value
ent
+--------+
| ent_id |
+--------+
| 1 |
| 2 |
| 3 |
+--------+
value
+--------+------------+
| ent_id | ent_id_val |
+--------+------------+
| 1 | NULL |
| NULL | 2 |
+--------+------------+
The ent_id can be in either colum of ent_id and ent_id_val in value table.
In the example above, I want the record ent_id = 3 to be deleted.
Below is what I have attempt, it does delete some, but I wonder why it does not delete all completely ? I still have record in ent table that is not being used in value table.
DELETE e.*
FROM ent e
LEFT JOIN value v1 on e.ent_id = v1.ent_id
LEFT JOIN value v2 on v2.ent_id_val = e.ent_id
WHERE v1.ent_id is null and v2.ent_id_val is null
OR