Solved

Reverse of inner join query

Posted on 2004-04-07
5
589 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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