Delete from table where key not found in other table?
mysql, sql, subquery
Solution
I prefer to use `JOIN` over subquery.
DELETE a FROM table_a a
LEFT JOIN table_2 b
ON a.ID = b.table_1_id
WHERE b.table_1_id IS NULL
- SEE SQLFiddle Demo
Problem
Table 1: - id - name Table 2: - id - other_table_id - table_1_id - .. Basically what I want to do is ``` Delete from table_1 where id not in (select table_1_id from table_2 group by table_1_id); ``` Which should work, what I am wondering is if the sub query is the best way to do this/ is there any other way?