Solved

Help with SQL Query

Posted on 2012-03-12
2
267 Views
Last Modified: 2012-03-12
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
0
Comment
Question by:tampsystems
2 Comments
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 37709479
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
0
 

Author Closing Comment

by:tampsystems
ID: 37709561
thanks, you saved me a ton of time today!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now