Solved

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

Posted on 2008-10-02
5
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 41

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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