We help IT Professionals succeed at work.

Help with SQL Query

We want to select all the rows that have an AID = 1 but don't have a matching AID = 2 with the same BID.

select ID, PersonID, AID, BID from [track] order by id

Tractrack table
Watch Question

select t1.ID, t1.PersonID, t1.AID, t1.BID
from [track] as t1
where not exists
(select 1
from track as t2
where t2.BID = t1.BID and T2.AID = 2
 order by t1.id


thanks, you saved me a ton of time today!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.