find common fields in 2 tables

Posted by Klbaiju under Sql Server on 8/10/2010 | Views : 4451 | Status : [Member] | Replies : 2
Hi,
I have 2 tables .
the tasks are

1. i want to display records common in 2 tables
tables are tourmaster and tourdetails.

2. display the records in tourdetails that is not available in tourmaster


Regards
Baiju




Responses

Posted by: Shankul2784 on: 8/10/2010 [Member] Bronze

Up
0
Down
Hi,

select * from tourmaster where columnName in (Select columnName from tourdetails)

select * from tourdetails where columnName not in (Select columnName from tourmaster)

I hope, this will help you.

Thanks & Regards,

Shailesh

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 8/10/2010 [Member] [MVP] Silver

Up
0
Down
Hi

1. Use JOIN
SELECT A.COLUMN1, B.COLUMN2 FROM tourmaster A(NOLOCK)
JOIN tourdetails B(NOLOCK)
ON (A.Column1 = B.Column1)

2. Use OUTER JOIN
SELECT A.COLUMN1, B.COLUMN2 FROM tourdetails A(NOLOCK)
LEFT JOIN tourmaster B(NOLOCK)
ON (A.Column1 = B.Column1)
WHERE B.Column1 IS NULL

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response