Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Get matching and non exist record of Detail table

Author  Topic 

thiyait
Yak Posting Veteran

70 Posts

Posted - 2009-03-31 : 00:54:24
Here is my query problem

Customer:
CustId CompanyName
------ -----------
10000 VSN labs
20000 cez labs
30000 win labs


Customer detail:
CustId Pincode
-------
10000 600 001
20000 500 001


I need to dispaly the value of customer who is having 600 001 and who doesn't have the customer details record.

Result should be like this
customer companyname
-------- -----------
10000 VSN labs
30000 win labs



could you help me out to get the records in single query..

Thanks in advance.

Thiya



Thiya
http://knowmoreax.blogspot.com/

abcd
Yak Posting Veteran

92 Posts

Posted - 2009-03-31 : 01:09:08
but why this record u want to have in ur output???

customer companyname
-------- -----------
10000 VSN labs
Go to Top of Page

matty
Posting Yak Master

161 Posts

Posted - 2009-03-31 : 01:37:28
SELECT C.CustId,CompanyName
FROM Customer c
LEFT JOIN CustomerDetail cd ON c.CustId = cd.CustId
WHERE cd.CustId IS NULL OR cd.PinCode = '600 001'
Go to Top of Page
   

- Advertisement -