Query the records that are not same in two different table.
-
Dear Experts, I am using MS SQL server 2005. I want to Query the records that are not same in two different table. ie., I have 2 different tables TABLE1, TABLE2 which are having same columns. (and most of the row are same) Q1 : I want to query the records of TABLE2 which are not avaliable in TABLE1 Q2 : I want to query the records of TABLE1 which are not avaliable in TABLE2 Needless to compare the primay key. Thanks in advance!!
-
Dear Experts, I am using MS SQL server 2005. I want to Query the records that are not same in two different table. ie., I have 2 different tables TABLE1, TABLE2 which are having same columns. (and most of the row are same) Q1 : I want to query the records of TABLE2 which are not avaliable in TABLE1 Q2 : I want to query the records of TABLE1 which are not avaliable in TABLE2 Needless to compare the primay key. Thanks in advance!!
SELECT a.*
FROM table1 a left outer join table2 b
--a.id, b.id are the columns that you would use to join the tables together
ON a.id = b.id
WHERE b.id IS NULLThat will show you a list of records that are not in table2.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
SELECT a.*
FROM table1 a left outer join table2 b
--a.id, b.id are the columns that you would use to join the tables together
ON a.id = b.id
WHERE b.id IS NULLThat will show you a list of records that are not in table2.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
Thanks a lot Simon_Whale But if I have one then one criatria to compare incase I also have a.id2 = b.id2..please suggest
-
Thanks a lot Simon_Whale But if I have one then one criatria to compare incase I also have a.id2 = b.id2..please suggest
the
ON
is what joins the two tables together is the second condition is more to restrict the results then you would put that in theWHERE
clause.Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
Dear Experts, I am using MS SQL server 2005. I want to Query the records that are not same in two different table. ie., I have 2 different tables TABLE1, TABLE2 which are having same columns. (and most of the row are same) Q1 : I want to query the records of TABLE2 which are not avaliable in TABLE1 Q2 : I want to query the records of TABLE1 which are not avaliable in TABLE2 Needless to compare the primay key. Thanks in advance!!
Records of TABLE2 which are not avaliable in TABLE1
select * from table2 where ColumnName not in (select ColumnName from table1 )
TABLE1 which are not avaliable in TABLE2
select * from table1 where ColumnName not in (select ColumnName from table2 )
I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post.
-
Dear Experts, I am using MS SQL server 2005. I want to Query the records that are not same in two different table. ie., I have 2 different tables TABLE1, TABLE2 which are having same columns. (and most of the row are same) Q1 : I want to query the records of TABLE2 which are not avaliable in TABLE1 Q2 : I want to query the records of TABLE1 which are not avaliable in TABLE2 Needless to compare the primay key. Thanks in advance!!