I'm working on merging an old database into a new one. In the new database I have four database tables: 'task_clone', 'potential_task', 'task' and 'task_archive'.
'task_clone' contains all the database entries of type task imported from the older database and I'm trying to distribute these entries across the other three tables in the new database. 'task_clone' is therefore a temporary table.
'task_clone' contains 649 entries. The structure of the data does not map very easily to the new database and after copying the rows from 'task_clone' the sum total of the other three tables entries is 566, which means there are 83 entries in 'task_clone' that have yet to be mapped into the new structure.
I'm trying to query 'task_clone' to figure out which entries are in the other three tables that are not in 'task_clone'.
All three tables contain the column 'task_id', which is unique id for each task entry. I should therefore be able to query the database and get all the 'task_id' columns in 'task_clone' returning the entires that do not match those in the other three tables.
I know this should be possible in a single query but I can't quite seem to get the syntax correct. Where am I going wrong and how should this be written? I initially tried:
SELECT task_clone.task_id FROM task_clone WHERE task_clone.task_id != potential_task.task_id AND task_clone.task_id != task.task_id AND task_clone.task_id != task_archive.task_id; I also looked at some other approaches to doing this with two tables (i.e. returning values from one that were not in the other) but I couldn't find an example that I could translate cleanly into a solution that would work for more than two tables without getting error messsages. Thanks for reading.
NOTE in response to this being marked as a duplicate: This question is not a duplicate of those previous questions which ask specifically about two tables since my question specially enquires about working with four tables. The solution supplied on the cited question, while using roughly the same syntax, does not provide a solution to the question of 4 tables. Further, in my question I clearly state that I've looked at previous stack answers that deal with two tables and I couldn't translate them to four without getting error messages.
... table1 LEFT JOIN table2 WHERE table1.column IS NULLor simply... table 1 WHERE id NOT IN(SELECT id FROM table2)