Solved

Reverse of inner join query

Posted on 2004-04-07
5
591 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
  • 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now