find discrepancy between two tables
-
Hi Experts, I have to find discrepancy between two tables I have Table 1 with columns OrderID Date Quantity Symbol Table 2 with columns OrderID Date Quantity Symbol I want a script to find out a list of OrderIDs present in table1 but not in table 2 and a list of OrderIDs present in table2 but not in table 1. Could any one help me in writing this query? Thanks in advance
-
Hi Experts, I have to find discrepancy between two tables I have Table 1 with columns OrderID Date Quantity Symbol Table 2 with columns OrderID Date Quantity Symbol I want a script to find out a list of OrderIDs present in table1 but not in table 2 and a list of OrderIDs present in table2 but not in table 1. Could any one help me in writing this query? Thanks in advance
You can use the IN oprator for that:
SELECT * FROM Table1 WHERE OrderID NOT IN ( SELECT OrderID FROM Table2 )
and then reverse the tabels for the other way:SELECT * FROM Table2 WHERE OrderID NOT IN ( SELECT OrderID FROM Table1 )
--------------------------- Blogging about SQL, Technology and many other things
-
You can use the IN oprator for that:
SELECT * FROM Table1 WHERE OrderID NOT IN ( SELECT OrderID FROM Table2 )
and then reverse the tabels for the other way:SELECT * FROM Table2 WHERE OrderID NOT IN ( SELECT OrderID FROM Table1 )
--------------------------- Blogging about SQL, Technology and many other things
If you are on SQL Serer 2005 then you can use Intersetion, Difference and Union rules of Set Theroy. select * from Table1 intersect select * from Table2 It will give you the common records in both select * from Table1 EXCEPT select * from Table2 above will give you difference
Naveed Kamboh Complexity kills, Write easy code for your self. Punjabi stuff
-
If you are on SQL Serer 2005 then you can use Intersetion, Difference and Union rules of Set Theroy. select * from Table1 intersect select * from Table2 It will give you the common records in both select * from Table1 EXCEPT select * from Table2 above will give you difference
Naveed Kamboh Complexity kills, Write easy code for your self. Punjabi stuff
When it is just the orderid's it is faster (performance wise) to just use the IN syntax.
--------------------------- Blogging about SQL, Technology and many other things