Interview question

  • I just had a phone interview and was wondering in someone could give me the answer to this question...

    What's the difference between UNION and UNIONALL?

     

    Thanks in advance

    -WM

  • From Books Online:

    UNION

    Specifies that multiple result sets are to be combined and returned as a single result set.

    ALL

    Incorporates all rows into the results, including duplicates. If not specified, duplicate rows are removed.

  • Union does an implicit Distinct on the recordsets being joined, Union All does not - you get All records.

     

     

  • UNION ALL also does not sort the records in the result set.  You get the results from the first query followed by the results of the second query. 

    So long, and thanks for all the fish,

    Russell Shilling, MCDBA, MCSA 2K3, MCSE 2K3

  • is the sorting in Union an artifact of the implicit Distinct?

  • Yes, and therefore not to be relied on.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply