Union and Union All

  • sanjeewan99

    Say Hey Kid

    Points: 700

    Hi Duncan Pryde,

    for your question

    #Query1 Answer is only A

    #Query2 Answer is A,A

  • Bob Razumich

    SSCrazy

    Points: 2042

    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.

  • Thomas Abraham

    SSChampion

    Points: 10761

    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

  • Duncan Pryde

    SSCertifiable

    Points: 7956

    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.

  • Toreador

    SSChampion

    Points: 11261

    I thought it looked familiar!

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

  • Dana Medley

    SSCertifiable

    Points: 6764

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



    Everything is awesome!

  • Duncan Pryde

    SSCertifiable

    Points: 7956

    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!

  • EL Jerry

    SSCertifiable

    Points: 7057

    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]

  • OzYbOi d(-_-)b

    Hall of Fame

    Points: 3994

    thanks for the question - cheers

  • Michael Poppers

    SSCrazy

    Points: 2134

    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).

  • Bronzo

    SSC Veteran

    Points: 231

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

  • Hardy21

    SSCrazy Eights

    Points: 9708

    Nice and easy ...

    Thanks

  • Skanker

    Hall of Fame

    Points: 3059

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

  • OCTom

    SSChampion

    Points: 11755

    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.

  • Iulian -207023

    SSCertifiable

    Points: 7509

    Nice one thank you

    Iulian

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

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