Solved

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

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
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 …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

15 Experts available now in Live!

Get 1:1 Help Now