Skip to content
Advertisement

Find rows that exist in one table and not the other

Assuming I have these two tables, I want to do 2 queries.

  1. Find the rows that are in final table but NOT in temp table based on their FileID Assuming we’re only looking at FileID = 1
FileID rate groupID destination Rate bDate eDate billID
1 123 1033 987 2 2020-01-01 2020-12-31 NULL
1 234 1052 985 2 2020-01-01 2020-12-31 NULL
  1. Find all rows that are in the temp table but NOT in the final table based on their FileID. Assuming we’re only looking at FileID = 1
FileID rate groupID destination Rate bDate eDate billID
1 123 1033 987 2 2020-06-06 2020-12-31 0/1/1

Is there an efficient query that can do this?

Advertisement

Answer

Left join, then select rows with null for the other table.

Here is an example. I’ve put in [etc] instead of typing out all the field names.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement