0

I want to compare two table in SQL server and find difference.

enter image description here

enter image description here

I want Warehouse and Product combination and see the difference. I am expecting to combine and display both table together and write Null if same data is not present in other table.

For Ex:

  1. New Jercy and IPHONE from both table and see what is difference in model and quantity.

  2. New Jercy and IPHONE combination and comapare with San Jose and Samsung and see the difference.

  3. San Jose and Samsung combination and compare with TableB having San Jose and Samsung.

Can anyone help me on this.

Thank you!

5
  • Please add the desired result. – McNets Feb 6 '20 at 20:39
  • 1
    could you please provide example of the data for both tables and final result set you want to receive? depending on your requirements you may want to use a JOIN of two tables or to combine two separate selects using EXCEPT – NikitaSerbskiy Feb 6 '20 at 20:40
  • Here's a guide how to ask question. dba.meta.stackexchange.com/questions/2976/… – Eric Feb 6 '20 at 20:41
  • Thank you for response Nikita. I am expecting to combine and display both table together and write Null if same data is not present in other table. – user12293246 Feb 6 '20 at 22:00
  • Have you even tried anything??? – Eric Feb 8 '20 at 0:31
3

Take a look at using the EXCEPT clause.

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-except-and-intersect-transact-sql?view=sql-server-ver15

SELECT WAREHOUSE, PRODUCT, MODEL, QUANTITY FROM Table1
EXCEPT
SELECT WAREHOUSE, PRODUCT, MODEL, QUANTITY FROM Table2
1
  • Thank you so much. It works :-) – user12293246 Feb 10 '20 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.