Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select only value?

Status
Not open for further replies.

chaoma

Technical User
Apr 17, 2005
101
US
Hello, could someone help me with the following problem. It seems to be easy, but I couldn't figure out how.


I have the table below (mytable)

p_id type date
1 AC 20050301
1 MK 20050401
1 AC 20050401
2 AC 20050901
2 AC 20050301
3 AC 20050301
3 MK 20050301

I would like to select an ID where type='AC', but no correspondence 'MK'. In this case it should return:

p_id type date
2 AC 20050901
2 AC 20050301

I was thinking of using self-join, but then p_id=2 doesn't have any 'MK' status.

Any help would be appreciate.
 
select pid, type, dateP
from #tab1 a
where not exists (select pid from #tab1 b where type = 'MK' and a.pid = b.pid)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top