How To Check get records

Posted by Santosh4u under Sql Server on 10/20/2010 | Points: 10 | Views : 1198 | Status : [Member] | Replies : 2
Hi All,

i have some doubt on sql server 2005,

i have one table called table1(id,name,dob,address) and having other table called table2(id,name,dob,address,salary)

i want the records from table2 of the combination(name,dob,address) which is not exist in tables1

if table2 (name,dob,addres) combination is exist in table1 then that record should exclude...



Regards
Santosh




Responses

Posted by: T.saravanan on: 10/21/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Santhosh,

Not Exist Condition:

select name,dob,address from table2 where id not in(select distinct id from table1)


Exist Condition:

select name,dob,address from table2 where id in(select distinct id from table1)


Refer this code its helpful to you.

Cheers :)

Thanks,
T.Saravanan

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

Posted by: PandianS on: 10/21/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

The combination of Name, DOB and Address of Table2 is not available in Table1.
It should work...
SELECT A.* FROM TABLE2 A(NOLOCK)

WHERE NOT EXISTS
(
SELECT 1 FROM TABLE1(NOLOCK) B WHERE B.NAME = A.NAME AND B.DOB = A.DOB AND B.[ADDRESS] = A.[ADDRESS]
)
Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

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

Login to post response