Solved

SQL Query: Query for items in one list but not in another.

Posted on 2008-10-02
5
156 Views
Last Modified: 2010-05-18
I'm trying to reconcile the results of two queries.  Both return a list of userID's but one list returns more than the other and they should be equal.

How can I construct a query that gives me the ID's that are in one query result set but missing from the other?

ie if query a return 1,2,3,4,5,6
and query b rtuen 1,3,6

I would want to know what is in set a that is not in set b and vice versa.
0
Comment
Question by:Paulconsulting
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22627699
select * from
(
query 1
) a
full outer join
(
query 2
)b on a.fieldval = b.fieldval
where a.fieldval is null or b.fieldval is null
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22627700
are they returned as records or in a comma delimited list like that?

0
 
LVL 40

Expert Comment

by:Sharath
ID: 22667094
Query1 EXCEPT Query2
It will give you the records returened by Query1 which are not returned by Query2.
Similarly
Query2 EXCEPT Query1.
Your both Query1 and Query2 should have same attibutes in SELECT statement.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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

20 Experts available now in Live!

Get 1:1 Help Now