Union and Union All

  • Hi Duncan Pryde,

    for your question

    #Query1 Answer is only A

    #Query2 Answer is A,A

  • Duncan Pryde (7/9/2012)


    Not a bad question, and got me thinking about other possible questions, so here goes - how many rows are returned in the two following cases?

    -- Query 1

    SELECT 'A'

    UNION ALL

    SELECT 'A'

    UNION

    SELECT 'A'

    -- Query 2

    SELECT 'A'

    UNION

    SELECT 'A'

    UNION ALL

    SELECT 'A'

    Try to guess first, then use MS to verify. 😀

    Knowing how sometimes several consecutive (or semi-consecutive) QOTDs have followed a theme, I can't help but wonder if Mr. Pryde just ruined someone's forthcoming submission.

  • Nice, simple, but useful question. THanks!

    I almost answered the question as I first misread it:

    SELECT 'A'

    UNION ALL

    (SELECT 'B'

    UNION

    SELECT 'A')

    Which gives the A,A,B I almost clicked on. I have my tea now, so everything is all right. 😉

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Bob Razumich (7/9/2012)


    Knowing how sometimes several consecutive (or semi-consecutive) QOTDs have followed a theme, I can't help but wonder if Mr. Pryde just ruined someone's forthcoming submission.

    It did occur to me (after I posted of course), but normally, people put "1" in the title if it's the first part of a series, so fingers crossed.

  • I thought it looked familiar!

    http://www.sqlservercentral.com/Questions/Tags/UNION/UNION/

  • Nice easy question. Great for a Monday morning to get some brain juices going. :doze:



    Everything is awesome!

  • Toreador (7/9/2012)


    I thought it looked familiar!

    http://www.sqlservercentral.com/Questions/Tags/UNION/UNION/

    I'm working backwards through the QODs at the moment after a bit of a gap, so hadn't seen the March 8th question. However, reading the discussion for the question it shows how important order of UNIONs and the addition or omission of parentheses are!

  • Nice and easy back-to-basics question. Thank you, Sanjeewan.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • thanks for the question - cheers

  • Toreador (7/9/2012)


    I thought it looked familiar!

    http://www.sqlservercentral.com/Questions/Tags/UNION/UNION/

    Except that the earlier QotD was more challenging for me (and I got it wrong because I thought UNION took precedence over UNION ALL) than this one (which had a set of parentheses forcing precedence).

  • Nice easy question but the parenthenses are meaningless in this question they have no impact on the results.

  • Nice and easy ...

    Thanks

  • Thanks for this question. After last wek it is just whats needed.

  • mike.broniszewski (7/9/2012)


    Nice easy question but the parenthenses are meaningless in this question they have no impact on the results.

    Neither does the UNION ALL.

  • Nice one thank you

    Iulian

Viewing 15 posts - 16 through 30 (of 37 total)

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