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 parent records that do not have childs

Author  Topic 

mikedp
Starting Member

2 Posts

Posted - 2010-04-19 : 08:12:53
Hi,
Let's say I have a table with Categories, and a table with Subjects that contain a CategoryID.
How can I get a list of Category records that do not have a Subject record linked to them?
Tnx
Mike

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-04-19 : 08:14:46
select c.* from categories c left join subjects s on s.CategoryID = c.CategoryID
where s.CategoryID is null
Go to Top of Page

mikedp
Starting Member

2 Posts

Posted - 2010-04-19 : 09:10:33
Tnx! That's it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-19 : 10:56:26
or
select c.* from categories c where not exists(select 1 from subjects where CategoryID = c.CategoryID)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-04-20 : 00:36:07
quote:
Originally posted by mikedp

Tnx! That's it.



welcome
Go to Top of Page
   

- Advertisement -