Results 1 to 4 of 4
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    How to get union query to pull data from another table based on a cell within the query?


    Confusing title. I apologize. Let me explain. I have two tables of customer complaints over the past two years, tbl2019 and tbl2020. I have the tables in a union query, qry20192020. I also have another table of manager information, tblManagers. I'm trying to figure out a way to populate ManagerName and ManagerNumber (which is in tblManagers) within the qry20192020 based on the Location, which is in all three tables. I have pasted the SQl code for the union query below.

    Code:
    SELECT EventNumber, SubmissionDate, SubmittedBy, CustomerAccount, CustomerFirstName, CustomerLastName, Location, HighLevelEvent, Status, Description, ActionTakenFROM 2019
    WHERE Event = "Yes"
    AND Status = "In Progress"
    
    
    UNION SELECT EventNumber, SubmissionDate, SubmittedBy, CustomerAccount, CustomerFirstName, CustomerLastName, Location, HighLevelEvent, Status, Description, ActionTaken
    FROM 2020
    WHERE Event = "Yes"
    AND Status = "In Progress";
    Can I do this within a union query or do I need to make a union table or something else? Thank you!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Why do you have a table for each year?

    You can either JOIN each SELECT to tblManagers or build another query that joins the UNION to tblManagers.

    Each location has only 1 manager?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    We've just always done it. Definitely makes it more difficult.

    How would I go about building another query that joins them? Like what would be the SQL?

    Yes each location has one manager.

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Never mind, I got it. Thank you!

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

Similar Threads

  1. Replies: 7
    Last Post: 08-10-2017, 12:53 AM
  2. Query pull data from another table
    By tareyj8569 in forum Queries
    Replies: 6
    Last Post: 08-23-2015, 10:43 AM
  3. Replies: 1
    Last Post: 06-12-2015, 02:02 PM
  4. Replies: 1
    Last Post: 07-12-2013, 01:48 PM
  5. Query to pull multiples of same data from a table
    By mpreston14 in forum Queries
    Replies: 1
    Last Post: 05-24-2013, 02:01 AM

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