I often get request to write puzzles using SQL Server. Today, I am presenting one very simple but very interesting puzzle.
What will be the output of following two SQL Scripts. First try to answer without running this two script in Query Editor.
Script 1
SELECT 1
UNION ALL
(SELECT 1
UNION
SELECT 2)
GO
Script 2
(SELECT 1
UNION ALL
SELECT 1)
UNION
SELECT 2
GO
Hint : This puzzle is based on my previous article SQL SERVER – Union vs. Union All – Which is better for performance?
Answer : SQL SERVER – Simple Puzzle Using Union and Union All – Answer
Reference : Pinal Dave (https://blog.sqlauthority.com)