In this dbfiddle demo I have a DELETE FROM... WHERE
at the end like so:
......
DELETE FROM data_table
WHERE
(location, param_id, ref_time, fcst_time) NOT IN (SELECT location, param_id, ref_time, fcst_time FROM sel1)
AND
(location, param_id, ref_time, fcst_time) NOT IN (SELECT location, param_id, ref_time, fcst_time FROM sel2);
Although it works, it seems unnecessarily wordy, and possibly also not optimal in terms of performance?
Is there any way in which this can be simplified, e.g. by using a single NOT IN
statement?
Because of the way that they are defined, there is no overlap/intersection between sel1
and sel2
.
status_table
has 8033 rows
data_table
has 116432724 rows
sel1
has 61860084 rows
sel2
has 53706188 rows
Numbers don't necessarily add up because it's a live database and data is going in all the time. And yes, at the moment there are few if any rows to delete because most/all of the data is current.