Solved

Help with SQL Query

Posted on 2012-03-12
2
268 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Question 5 26
SQL Server stored proc 2 13
ms sql last 8 weeks as columns 5 28
use lov values 2 32
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

920 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