SQL SERVER – Simple Puzzle Using Union and Union All – Answer

Yesterday I posted a puzzle SQL SERVER – Simple Puzzle Using Union and Union All, today we will see the answer of this. Following image explains the answer of puzzle.

SQL SERVER - Simple Puzzle Using Union and Union All - Answer puzzlesunion

You can read the explanation of why this is answer read my previous article SQL SERVER – Union vs. Union All – Which is better for performance?

Reference : Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
, ,
Previous Post
SQL SERVER – Simple Puzzle Using Union and Union All
Next Post
SQLAuthority News – Few Links About SQLAuthority

Related Posts

7 Comments. Leave new

  • this is because of union, when ur using union in record than it shows distinct records

    Reply
  • yep, the perenthesis are rearanging the order of the unions which is causing the
    1 union all (1 union 2) to
    (1 union all 1) union 2

    trixy!

    Reply
  • A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.

    If we use another UNION between both scripts it will return (1,2)

    Reply

Leave a Reply

Menu