Union results

  • Good question, highlighting that union doesn't simply remove a duplicated row where the duplicate exists on both sides of the union, but will also remove a duplicated row where the duplicate rows exist on one side of the union.

  • .Thanks for the question

    ---------------------------------------------------------------------
    Use Full Links:
    KB Article from Microsoft on how to ask a question on a Forum

  • Cliff Jones (9/22/2011)


    Yes, I saw 1,2,3 and almost forgot to count the null value. Good straight forward question with all the likely wrong answers.

    I did forget to count the NULL 🙁

  • SQL Kiwi (9/22/2011)


    Cliff Jones (9/22/2011)


    Yes, I saw 1,2,3 and almost forgot to count the null value. Good straight forward question with all the likely wrong answers.

    I did forget to count the NULL 🙁

    This makes me feel much better. Thanks for being honest 😀

    /* Anything is possible but is it worth it? */

  • SQL Kiwi (9/22/2011)


    Cliff Jones (9/22/2011)


    Yes, I saw 1,2,3 and almost forgot to count the null value. Good straight forward question with all the likely wrong answers.

    I did forget to count the NULL 🙁

    I nearly missed the null. I glanced over it and then rechecked just before submitting.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Interesting question!!

    Thanks.

  • Easy question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Good question.

    I nearly counted NULL twice, but remembered in time that the deduplicate operation uses the version of "=" that makes NULL = NULL true.

    Tom

  • Nice question, thanks!

  • I found it interesting that the execution plan for the union in the question was the same as if I had done a distinct from the union all

    select distinct a from

    (select a from a

    union all

    select a from a) b

    In both cases, it did a Concatenation of the two result sets then did a Distinct Sort.

    It makes perfect sense that this is how the process would work, once I looked at it, but I thought it was interesting regardless.

    I'm pretty easily amused though. :w00t:

  • Easy & Straight forward question..

    Thanks

  • SQL Kiwi (9/22/2011)


    Cliff Jones (9/22/2011)


    Yes, I saw 1,2,3 and almost forgot to count the null value. Good straight forward question with all the likely wrong answers.

    I did forget to count the NULL 🙁

    +1

    I didn't see it at all. My bad.

    -- Gianluca Sartori

  • Good question.

    I didn't realize that the union would affect the first table as well. Was expecting both of the 1's to still be intact and therefore give 5 instead of 4......

Viewing 13 posts - 16 through 27 (of 27 total)

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