Select unmatched data from two columns

  • Interesting qotd.

  • So many words for a Monday morning question; I ended up reading it 4 or 5 times before answering. :hehe:

    Thank you very much, it was a good one.



    Everything is awesome!

  • The oddity that I find interesting about this question is the fact that the UNION automatically sorts the results. In my head I'm thinking the results would be 4,7,2,8 and 2,8,4,7 from the two correct options.

    ***I now see that using the UNION ALL would not do the sorting to look for duplicates and would have given me the results that I expected.

    Aigle de Guerre!

  • Great question. Gave me something to think about.

  • Meow Now (11/26/2012)


    The oddity that I find interesting about this question is the fact that the UNION automatically sorts the results. In my head I'm thinking the results would be 4,7,2,8 and 2,8,4,7 from the two correct options.

    ***I now see that using the UNION ALL would not do the sorting to look for duplicates and would have given me the results that I expected.

    It depends on the physical implementation of the UNION / UNION ALL by the query optimizer. Depending on your SQL Server version, you will / might see different results with e.g. OPTION (HASH UNION) or OPTION (MERGE UNION). As always, ORDER BY is required for output ordering guarantees 🙂

  • A headscratcher... but a nice one. Thanks!

  • Took a bit to think over since there were so many lines of code, but a good question anyways. Thanks!

  • Nice One, +1

  • Hmm. Selected 1 and 3 and was told wrong.

Viewing 9 posts - 16 through 24 (of 24 total)

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