Results 1 to 6 of 6
  1. #1
    gkaro is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    18

    UnionALL

    Hello All,

    I have many tables that I consolidate with a UnionALL query.
    One common field in every table is [YEAR]
    What I would like to do is filter in the main union query all records that are 2011 or 2012 only.

    This is what I have

    SELECT * FROM [SEARS]


    UNION ALL SELECT * FROM [FS/BB]
    UNION ALL SELECT * FROM [COSTCO]
    UNION ALL SELECT * FROM [HBC]
    UNION ALL SELECT * FROM [WALMART]
    UNION ALL SELECT * FROM [HOME DEPOT]
    UNION ALL SELECT * FROM [LOWES]
    UNION ALL SELECT * FROM [SALES IN]
    UNION ALL SELECT * FROM [BEDBATH]
    UNION ALL SELECT * FROM [CANTIRE]
    UNION ALL SELECT * FROM [CORBEIL]
    UNION ALL SELECT * FROM [BRICK]
    UNION ALL SELECT * FROM [TSC]
    UNION ALL SELECT * FROM [TEMP POS]
    UNION ALL SELECT * FROM [LEONS];

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You would either need to add a WHERE clause to each SELECT statement in the UNION, or base a second query on the UNION and put your criteria there. I assume you know it is a normalization mistake to have all those tables.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gkaro is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    18
    Yes, I do now.
    Created this as my first project. I realized that this sloooooows things down tremendously. Is this the reason its "incorrect" or is there more?

    thanks for the help.
    G

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No, that's just a side effect. Let's say you start dealing with a new store called "Baldys". In a normalized db, your users just add a record to your "stores" table via the form you would have built for that purpose, and it flows through the application without any design changes by you. In your design, you have to build a new table, presumably a new form, your UNION query has to be modified, and who knows what other forms, queries and reports have to be modified to account for the new store.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Yes, is bad design. If you use the UNION as source data for multitude of queries, forms, reports, maybe the required changes will be minimal but still a design change. Also, I have encountered a limit of 50 lines in a UNION and VBA would not play nice with UNION query. Had to modify a process to not rely on UNION so VBA code would work.
    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.

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    And Union Queries are not updatable as well.

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

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