G
Guest
I want to be able to take two tables I have and join them into 1 linking it
by last name and first name. The first name in table 1 is the actual first
name, but the first name in table 2 include first name and middle initial.
My query needs to be able to find all records that are the same from both
tables and all records that are not the same in both tables. I am trying to
use a UNION but i do not seem to get all the results I want. What am I doing
wrong? Should I not use a Union? I don't want to use a JOIN because I can't
get all the records from both tables.
SELECT [FIRM DIRECTORY].LASTNAME, [FIRM DIRECTORY].FIRSTNAME,
[TBLEMPMASTER].LASTNAME, [TBLEMPMASTER].FIRSTNAME,
[TBLEMPMASTER].[SOCIALSECURITY#]
FROM [FIRM DIRECTORY], TBLEMPMASTER
WHERE [FIRM DIRECTORY].LASTNAME=[TBLEMPMASTER].LASTNAME AND LEFT([FIRM
DIRECTORY].FIRSTNAME,2)=LEFT([TBLEMPMASTER].FIRSTNAME,2)
UNION
SELECT [FIRM DIRECTORY].LASTNAME, [FIRM DIRECTORY].FIRSTNAME,
[TBLEMPMASTER].LASTNAME, [TBLEMPMASTER].FIRSTNAME,
[TBLEMPMASTER].[SOCIALSECURITY#]
FROM [FIRM DIRECTORY], TBLEMPMASTER
ORDER BY [FIRM DIRECTORY].LASTNAME;
by last name and first name. The first name in table 1 is the actual first
name, but the first name in table 2 include first name and middle initial.
My query needs to be able to find all records that are the same from both
tables and all records that are not the same in both tables. I am trying to
use a UNION but i do not seem to get all the results I want. What am I doing
wrong? Should I not use a Union? I don't want to use a JOIN because I can't
get all the records from both tables.
SELECT [FIRM DIRECTORY].LASTNAME, [FIRM DIRECTORY].FIRSTNAME,
[TBLEMPMASTER].LASTNAME, [TBLEMPMASTER].FIRSTNAME,
[TBLEMPMASTER].[SOCIALSECURITY#]
FROM [FIRM DIRECTORY], TBLEMPMASTER
WHERE [FIRM DIRECTORY].LASTNAME=[TBLEMPMASTER].LASTNAME AND LEFT([FIRM
DIRECTORY].FIRSTNAME,2)=LEFT([TBLEMPMASTER].FIRSTNAME,2)
UNION
SELECT [FIRM DIRECTORY].LASTNAME, [FIRM DIRECTORY].FIRSTNAME,
[TBLEMPMASTER].LASTNAME, [TBLEMPMASTER].FIRSTNAME,
[TBLEMPMASTER].[SOCIALSECURITY#]
FROM [FIRM DIRECTORY], TBLEMPMASTER
ORDER BY [FIRM DIRECTORY].LASTNAME;