Link to home
Start Free TrialLog in
Avatar of dgelinas
dgelinasFlag for United States of America

asked on

Reverse of inner join query

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);
Avatar of nico5038
nico5038
Flag of Netherlands image

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)
Avatar of dgelinas

ASKER

I was hoping for an easier solution in SQL. I'll try what you suggest but it sounds a little hairy.
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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