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

    Sort by column in a UNION ALL query

    How would I sort ascending by my "name" column in my UNION ALL query? The "name" column is the third column in (if that matters)



    My current SQL is:

    SELECT * FROM 2019
    UNION ALL
    SELECT * FROM 2018;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you need another query
    1. the Union query, qnUnion
    2. sort the query

    select * from qnUnion order by [NAME]

    Run Q2.

  3. #3
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    Or your query can be rewritten to:

    SELECT * FROM (SELECT * FROM 2019 UNION ALL SELECT * FROM 2018) as tbl1 ORDER BY [Name]

  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,652
    Have you tried

    SELECT * FROM 2019
    UNION ALL
    SELECT * FROM 2018
    ORDER BY [Name]

    or by position

    SELECT * FROM 2019
    UNION ALL
    SELECT * FROM 2018
    ORDER BY 3
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 08-11-2014, 10:14 AM
  2. Sort Date in SQL UNION statement
    By KWarzala in forum Forms
    Replies: 5
    Last Post: 08-08-2014, 08:42 AM
  3. Replies: 1
    Last Post: 12-09-2013, 05:57 PM
  4. 3-column sort in a query
    By JeanZander in forum Queries
    Replies: 11
    Last Post: 12-28-2012, 05:50 PM
  5. Replies: 3
    Last Post: 04-19-2011, 06:41 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