Results 1 to 5 of 5
  1. #1
    afslaughter is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    9

    Join 2 Querys

    I am very new to MS Access.
    I am trying to join the results of 2 separate queries and I can't figure it out.

    This is what I have so far. I made 2 queries and copied the SQL code from each and tried to make one Union Query.

    Query1:
    (SELECT [UMPR Dump].SSN, "N/A" AS Name, "Not in Data Base" AS Status
    FROM [UMPR Dump] LEFT JOIN Data ON [UMPR Dump].SSN = Data.SSN
    WHERE (((Data.SSN) Is Null)))


    Query2:
    (SELECT Data.SSN, [Last] & " " & [First] & " " & [Middle] AS Name, "Not in UMPR" AS Status
    FROM Data LEFT JOIN [UMPR Dump] ON Data.SSN = [UMPR Dump].SSN
    WHERE ((([UMPR Dump].SSN) Is Null) AND ((Data.Archived)=0)))



    My horrible attempt at a Union Query:
    SELECT Union.SSN, Union.Name, Union.Status
    FROM

    (SELECT [UMPR Dump].SSN, "N/A" AS Name, "Not in Data Base" AS Status
    FROM [UMPR Dump] LEFT JOIN Data ON [UMPR Dump].SSN = Data.SSN
    WHERE (((Data.SSN) Is Null)))

    As Union INNER JOIN
    (SELECT Data.SSN, [Last] & " " & [First] & " " & [Middle] AS Name, "Not in UMPR" AS Status
    FROM Data LEFT JOIN [UMPR Dump] ON Data.SSN = [UMPR Dump].SSN
    WHERE ((([UMPR Dump].SSN) Is Null) AND ((Data.Archived)=0)))




    Thanks for any help I can get.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What are you attempting to accomplish? What is the final result suppose to be?

    What does the data represent?

  3. #3
    afslaughter is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    9
    Well I have 2 Tables "Data", "UMPR Dump"
    The Data table has everything in my Dbase.
    The UMPR is an outside report that I want to compare with the "Data Table".
    I paste the SSN from the report to a table in my Dbase called "UMPR Dump".
    The comparison I want to make is:

    1: SSN on the UMPR that are not in Data
    2: SSN in Data that are not on the UMPR

    I was able to do this with 2 separate queries. They work great and produce a list with 3 columns SSN, Name, Status. Like This:

    Query 1:
    SSN - Name - Status
    234 - N/A - Not in Data
    267 - N/A - Not in Data

    Query 2:
    SSN - Name - Status
    123 - Bob - Not in Umpr
    122 - Rob - Not in Umpr
    345 - John - Not in Umpr


    I want to combine the 2 into 1 list like:

    SSN - Name - Status
    123 - Bob - Not in Umpr
    234 - N/A - Not in Data
    122 - Rob - Not in Umpr
    345 - John - Not in Umpr
    267 - N/A - Not in Data

  4. #4
    mejia.j88 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    california
    Posts
    228
    it should look something like this:

    SELECT SSN, NAME, STATUS
    FROM DATA
    UNION ALL
    SELECT SSN, NAME, STATUS
    FROM UMPR;

    that's assuming i have the correct fields from their appropriate table. let me know if this helps

  5. #5
    afslaughter is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    9

    Solved

    That’s it, thanks so much. I knew it had to be something simple.
    Here is my final code:


    SELECT SSN, NAME, STATUS
    FROM
    (SELECT [UMPR Dump].SSN, "N/A" AS Name, "Not in Data Base" AS Status
    FROM [UMPR Dump] LEFT JOIN Data ON [UMPR Dump].SSN = Data.SSN
    WHERE (((Data.SSN) Is Null)))
    UNION ALL
    SELECT SSN, NAME, STATUS
    FROM
    (SELECT Data.SSN, [Last] & " " & [First] & " " & [Middle] AS Name, "Not in UMPR" AS Status
    FROM Data LEFT JOIN [UMPR Dump] ON Data.SSN = [UMPR Dump].SSN
    WHERE ((([UMPR Dump].SSN) Is Null) AND ((Data.Archived)=0)));

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Outer Join Nested in Inner Join
    By Stevens7 in forum Queries
    Replies: 2
    Last Post: 10-19-2011, 01:34 PM
  2. Report with two querys
    By karanvemuri in forum Reports
    Replies: 3
    Last Post: 10-03-2011, 09:36 AM
  3. Help making a form with tables and querys
    By mentose457 in forum Forms
    Replies: 2
    Last Post: 12-06-2010, 06:00 PM
  4. Where are my Querys?
    By tamu46 in forum Access
    Replies: 7
    Last Post: 12-04-2010, 03:27 AM
  5. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums