Solved

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

Posted on 2008-10-02
5
174 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

627 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