I need to delete records that are present in the destination table but not in the source table. The primary key in the destination table is an auto_increment ID which is not there in the source table. Both the source and destination tables contain a set of unique key combinations which can be used to uniquely identify the rows in either tables. What is the approach that I should follow? How can I delete if I am to use multiple column combinations as the unique key and not one primary key(not there in source)?
delete from dest_table
where (uniq_key_col1,uniq_key_col2) not in (
select dest.uniq_key_col1,dest.uniq_key_col2
from dest_table dest
join source_table source
on dest.uniq_key_col1=source.uniq_key_col1
and dest.uniq_key_col2=source.uniq_key_col2
)
This is how it should ideally look (provided just for clarity and please ignore the error in where clause because of multiple columns)