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
Solved

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Agent Timeout 5 65
SQL Syntax:  How to Find Commonality Among Similar Results 2 54
Unable to save view in SSMS 21 73
Please help for the below sql query. 1 28
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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