Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    280

    Unanswered: How do you create a UNION query with the WHERE and ORDER BY clause.

    I have try running a UNION query with only the where clause and it works but unable to get the query to work with the WHERE and ORDER BY clause in the query at the same time. What would be the problem?

    For example:
    Select mailnum As ID, maildesc as Description
    From Mail
    Where ID="1"
    Order By mailDate

    UNION

    Select shippingnum As ID, shippingdesc as Description
    From Shipping
    Where ID="2"
    Order By shippingDate

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What are you trying to do, exactly?

    You can't use order by in a subquery or a component of a union statement, that wouldn't make any sense. What is your desired resultset?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Apr 2003
    Posts
    280
    Nevermind, I got it. I just find out the UNION clause only accepts one ORDER BY clause, which should be at the end of the query.

    Select mailnum As ID, maildesc as Description, mailDate as Datee
    From Mail
    Where ID="1"

    UNION

    Select shippingnum As ID, shippingdesc as Description, shippingDate as Datee
    From Shipping
    Where ID="2"
    Order By Datee

    Thanks anyways!

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Now THAT makes more sense...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •