There are 3 tables
a simple mock up....
table_1 table_2 table_3 id id id 1 1 2 2 2 3 3 5 4 5 6 5 7 8 6 9 7 8 9 10
Now here's what I want to do...
Join tables table_1 and table_2 first, using id so that I get an intersection of ids in the tables
again an example
result of join 1 table_1 table_2 id other_table_1_data... id other_table_2_data... 1 1 2 2 3 NULL 5 5 NULL 6 7 NULL NULL 8 9 NULL
As you can see a simple LEFT/RIGHT join wouldn't help since I'll only get all rows in one table for that but what I want is an intersection of rows in tables 1 and 2.
The next part is relatively simple and I guess I have that figured out, I need to compare this result table with table_3 to see which records in the result Set are not present in table_3 so a simple LEFT join outta do it.
Then I need to delete rows from table_1 and table_2 that are not present in table_3. I can do this separately using table 1 and 3 on left join and then table 2 and 3, but doing them in one query could definitely save resources since it runs every 15 minutes on my already overloaded server.