Skip to Main Content

Write Great SQL Office Hours

Free tips and training every month! Subscribe for reminders and more from Office Hours. FAQ

Header container

October 17, 2023

13:00 UTC   Start Times Around the World

Subscribe to be notified of changes to sessions and give us feedback!

Having trouble watching the video on this page? Open the video in your browser.


How to compare two tables with SQL
Often you want to compare two tables to see if there are any differences in their rows.

The classic way to do this is with set operations. But this means reading all of both tables twice!

In this session, we'll look at other methods to do this, including full outer joins and group by queries.

Highlights include:

00:50 - Using set operations to compare tables
03:20 - Using full outer joins to compare tables
10:35 - Using group by to compare tables
13:50 - Demo of set operation method
15:15 - Demo of full outer join methods
19:00 - Demo of group by method
25:50 - Table comparison methods summary
27:50 - SQL macro comparison functions
29:50 - Comparing queries
31:40 - Finding table changes over time
34:20 - Unpivot to get column differences as rows
36:55 - Demo of comparison macro
37:50 - Demo of comparing queries
41:10 - Demo of finding table changes
43:20 - Demo of column differences
46:10 - Performance comparison demo
55:05 - Cheat sheet of approaches

Get the scripts ml
Read the blog post -rows-with-sql

Test your SQL syntax knowledge with SQuizL; a free, daily guess the SQL statement quiz

Your Experts

    Chris Saxon

    Chris Saxon   

    Chris Saxon is an Oracle Developer Advocate and quizmaster on Dev Gym. His job is to help you get the best out of the Oracle Database and have fun with SQL! He's also part of the answer team on Ask TOM and creates YouTube videos at The Magic of SQL channel.