Results 1 to 7 of 7
  1. #1
    isegui2004 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2023
    Posts
    2

    Querying 3 or more tables at once


    I have three tables that have identical fields with data from different time periods (ie 2021, 2022, 2023). Is there a way to join all three tables to be able to create a query that pulls from all tables?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    If the info is basically the same but you have a table for each year, then this is the wrong design approach and that needs to be fixed. Otherwise join each table in a query, using whatever fields contain the same related information in at least pairs of tables (i.e. tblA can be related to tblB and tblB to tblC, or perhaps tblA to tblC). I expect that the design is incorrect, thus you might have to post some data samples (copy/paste from Excel is much better than pics) in order to provide focused answers.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    229
    I agree with Micron that this is bad design. But I don't think his solution is right. Do not join the tables but union them. Something like:
    Code:
    SELECT * FROM T1
    UNION 
    SELECT * FROM T2 
    UNION 
    SELECT * FROM T3
    Groeten,

    Peter

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    And I agree with xps35 except I would use UNION ALL. UNION on it's own will remove duplicates. It is quite possible you have no duplicated data within the same year or across the years, but on the other hand, you might.

    Note that union queries prevent the use of indexing so using this as a base query which other queries reference will be slow compared with a normalised structure (which in principle simply requires a 'year' column in a table - or perhaps you already have a date column from which a year can be determined)

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    As stated above, this is a poor design choice

    I don't think using UNION/UNION ALL query or a query with 2 JOINS is the best solution.
    Apart from anything else, the UNION queries will be read only (as it probably would be using JOINS)

    The tables have identical fields so the data should be in one table with an additional field if necessary to denote the year.
    If the 3 tables already contain a date field, doing that isn't even necessary.

    By all means, use a UNION ALL query as the first step, then use a MAKE TABLE or append query to create a new single table from that
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    isegui2004 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2023
    Posts
    2
    These are very big datasets. I used to have a master table but it kept crashing because of size. I’m trying to find an alternative where I can query the data from multiple tables without combining all the data into one table.

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    I don't think your db crashed because of the size of one table. The limit is 2Gb including overhead. 3 tables can reach the size limit sooner than one table with all the records because each table adds overhead. Your design likely caused the crashing, but there's no way to know exactly what the cause might have been - unless maybe you got a helpful error message when it crashed.

    As for the way to get the data out, I have to admit I likely missed the mark.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Querying multiple tables
    By rassoc in forum Queries
    Replies: 4
    Last Post: 09-01-2022, 08:15 AM
  2. Querying cascading tables
    By Brownie1987 in forum Queries
    Replies: 7
    Last Post: 11-05-2017, 01:45 PM
  3. Querying linked tables
    By atbm in forum Queries
    Replies: 5
    Last Post: 08-04-2017, 02:35 PM
  4. Querying 2 or more tables
    By NewbieInCT in forum Queries
    Replies: 12
    Last Post: 05-11-2012, 09:49 AM
  5. Querying from 2 tables
    By egnaro in forum Queries
    Replies: 6
    Last Post: 01-28-2010, 06:30 PM

Tags for this Thread

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