Skip to content
Advertisement

How to compare two snaps of schema data in SQL?

I have two tables:

Current_Ranking:

Previous_Ranking

I want to get as a result all records in Previous_Ranking that don’t appear in Current_Ranking (means new id) and all records that their rank in Previous_Ranking is not the same as Current_Ranking

So expected result is:

How can I do that? I know I can do:

This should give me all the new rows. But How I continue from here?

I’m using BigQuery so this can be done with native SQL.

Advertisement

Answer

You may use a left join with two criteria:

enter image description here

Note: RANK is a reserved keyword in many versions of SQL (though apparently not in BigQuery). So, you might want to avoid using RANK as a name for columns and tables.

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