Retrieve records from two tables

Posted by nayeemdotnetfunda-27597 under Sql Server on 7/28/2014 | Points: 10 | Views : 409 | Status : [Member] | Replies : 3
I have two tables Class1 and Class2 how to retrieve all the records of Class1 those shouldnot present in Class2




Responses

Posted by: Rasikbapotra on: 7/28/2014 [Member] Starter | Points: 25

Up
0
Down
Hi Nayeem,

You can try below query

SELECT * from Class1.* LEFT JOIN Class2 ON Class1.ColumnName <> Class2.ColumnName

nayeemdotnetfunda-27597, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 7/30/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Use Except set operator f you have same structure for both tables,
SELECT * FROM Class1
EXCEPT
SELECT * FROM Class2


If you have one common column between both tables, use LEFT JOIN
SELECT c1.* FORM Class1 c1 LEFT JOIN Class c2 ON c1.CommonColumn = c2.CommonColumn




Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

nayeemdotnetfunda-27597, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/1/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
If u got solution/help from the above replies, make them as Answered.. Else, post us back the sample data and expected output

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

nayeemdotnetfunda-27597, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response