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.

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 (http://blog.SQLAuthority.com)

6 thoughts on “SQL SERVER – Simple Puzzle Using Union and Union All – Answer

  1. Pingback: SQL SERVER - Simple Puzzle Using Union and Union All Journey to SQL Authority with Pinal Dave

  2. 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!

    Like

  3. Pingback: SQL SERVER – Weekly Series – Memory Lane – #022 | SQL Server Journey with SQL Authority

  4. Pingback: SQL SERVER – UNION ALL and UNION are Different Operation | SQL Server Journey with SQL Authority

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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s