Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001


    Quote Originally Posted by printsol View Post
    I think in union all tables must have same fields name????
    No just the same data types (I think, I'm not sure I have ever tried different datatypes??) and you must select the same number of columns

    SELECT f1, f2, f4, f6 FROM Table1

    Union

    SELECT f01, f02, f04, f09 FROM Table2

    Would be perfectly valid.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    If there are not the same number of fields, use a filler - I prefer Null.

    First SELECT determines field names and types unless data is mixed in a column then all in that column will be strings regardless of what the first SELECT contains. Multi-value field cannot be used in UNION.

    SELECT f1, f2, f4, f6 AS Data FROM Table1

    UNION

    SELECT f01, f02, Null, f09 FROM Table2;
    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. #18
    Join Date
    Apr 2017
    Posts
    1,673
    Quote Originally Posted by printsol View Post
    I think in union all tables must have same fields name????
    Not really! Field count must be same for all subqueries, and fields in same position must be of same type (but e.g. text fields can be of different length) in all subqueries. The result table inherits field names from 1st subquery.

  4. #19
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    No, fields in same position do not have to be same type. They must be same type if you want to do some sort of operation, such as Sum or DateDiff.
    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.

  5. #20
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Quote Originally Posted by printsol View Post
    I think in union all tables must have same fields name????
    No, but the position of the fields should be of the same data type. IIRC, the output field names are those from the table in the first part of the Union.

    EDIT - don't have to be of the same type, but if they are not, you can get unexpected results, especially if Nulls are involved.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 12-24-2019, 10:46 AM
  2. Replies: 2
    Last Post: 05-21-2017, 05:40 PM
  3. Replies: 2
    Last Post: 05-15-2014, 06:15 AM
  4. Calculating columns in crosstab query
    By GraemeG in forum Queries
    Replies: 11
    Last Post: 06-05-2011, 06:43 PM
  5. Calculating the Sum of Mulitple Columns
    By ARickert in forum Queries
    Replies: 22
    Last Post: 12-27-2010, 09:06 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