SQL Server: Using EXCEPT find Mismatch rows from two tables

In this post, I am showing very command and important solution to find all mismatch rows from two tables of SQL Server.

Many times, I have found that my coworker are finding mismatch rows using NOT IN and EXISTS operators which are not advisable to execute over the big size of the table.

Please do not use NOT IN and EXISTS operators for finding mismatch rows from different tables. I am sharing quick note on this.

SQL Server has one very good Set Operators which is EXCEPT.
The EXCEPT returns distinct rows from the left table that are not output from the right table.

Below is a small demonstration:

First create two test table, one is Source and second is Destination:

Insert sample data into both table with some different values:

You can find that Name with “Alia” is not available in the Destination Table.

Find mismatch rows using EXCEPT:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of