Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reverse of inner join query

Posted on 2004-04-07
5
Medium Priority
?
599 Views
Last Modified: 2008-03-17
The query below does a match between 2 tables and returns 4,100 records. I would now like to run a query that returns the gap which is 472 records (the unmatched records not returned from the HR_CTI table). Basically, I need to inverse the query to find those records that did not match. Hope this makes sense.

SELECT GD_Dump.ID, GD_Dump.EMPLID, GD_Dump.LAST_NAME, GD_Dump.FIRST_NAME, GD_Dump.NAME, GD_Dump.LOCATION, GD_Dump.DESCR, GD_Dump.ADDRESS1, GD_Dump.ADDRESS2, GD_Dump.ADDRESS3, GD_Dump.CITY, GD_Dump.STATE, GD_Dump.POSTAL, GD_Dump.PHONE, GD_Dump.COUNTRY
FROM GD_Dump INNER JOIN HR_CTI ON (GD_Dump.FIRST_NAME = HR_CTI.Fname) AND (GD_Dump.LAST_NAME = HR_CTI.Lname);
0
Comment
Question by:dgelinas
[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
  • 2
5 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 10775310
In the query editor double click the join lines and make one table "leading"
Next make the unique ID of the "optional" table to be compared with "Is Null" (without quotes)

This will give the half of the outer join needed as all non-matching from the leading table will appear.

Next do the same "the other way around" to get the second half.

A UNION query can be used when you want the complete set.

Clear ?

Nic;o)
0
 
LVL 6

Author Comment

by:dgelinas
ID: 10775323
I was hoping for an easier solution in SQL. I'll try what you suggest but it sounds a little hairy.
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 1000 total points
ID: 10775444
It's all SQL, just gave the directions to use the graphical query editor as it'is easy to see the relation and to know what main key need to be tested for being Null.

Like
TableX -> TableY
test ID from TableY to be null to get the non-matching TableX rows
TableX <- TableY
test ID from TableX to be null to get the non-matching TableY rows

Nic;o)
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10775463
to find the records in GD_DUMP that ARE NOT in HR_CTI:

SELECT GD_Dump.ID, GD_Dump.EMPLID, GD_Dump.LAST_NAME, GD_Dump.FIRST_NAME, GD_Dump.NAME, GD_Dump.LOCATION, GD_Dump.DESCR, GD_Dump.ADDRESS1, GD_Dump.ADDRESS2, GD_Dump.ADDRESS3, GD_Dump.CITY, GD_Dump.STATE, GD_Dump.POSTAL, GD_Dump.PHONE, GD_Dump.COUNTRY
FROM GD_Dump LEFT JOIN HR_CTI ON (GD_Dump.FIRST_NAME = HR_CTI.Fname) AND (GD_Dump.LAST_NAME = HR_CTI.Lname) where HR_CTI.FNAme is Null;

you can also build this easily with the Access Query Builder, using the UnMatched Query Wizard (Query Builder/New/UnMatched Query Builder)

AW
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

660 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