Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


T-SQL Output Query | [ The JOIN Puzzle – Part 4 ( Join with an Empty Set ) ]

–Let’s say we have 2 table TestJoins5 and TestJoins6. Both the tables having only one ID column. Here you have to provide the output of the queries given below. Before that please go through the input data below.

Update – Added Outputs below – 17 Sep 2015

Pawan Kumar Khowal - Join Table 1

Pawan Kumar Khowal – Join Table 1

Pawan Kumar Khowal - Join Table 2

Pawan Kumar Khowal – Join Table 2


--

CREATE TABLE TestJoins5
(
	ID INT 
)
GO

INSERT INTO TestJoins5 VALUES (NULL),(NULL)
GO

CREATE TABLE TestJoins6
(
	ID INT 
)
GO

--Query 1
SELECT t1.ID , t2.ID FROM [dbo].[TestJoins5] t1 INNER JOIN [dbo].[TestJoins6] t2  ON t1.ID = t2.ID
 
--Query 2
SELECT t1.ID , t2.ID FROM [dbo].[TestJoins5] t1 LEFT OUTER JOIN [dbo].[TestJoins6] t2  ON t1.ID = t2.ID
 
--Query 3
SELECT t1.ID , t2.ID FROM [dbo].[TestJoins5] t1 RIGHT OUTER JOIN [dbo].[TestJoins6] t2  ON t1.ID = t2.ID
 
--Query 4
SELECT t1.ID , t2.ID FROM [dbo].[TestJoins5] t1 FULL OUTER JOIN [dbo].[TestJoins6] t2  ON t1.ID = t2.ID

--Query 5
SELECT t1.ID , t2.ID FROM [dbo].[TestJoins5] t1 CROSS JOIN [dbo].[TestJoins6] t2

--

Output of the above puzzles is given below-

Pawan Khowal - Join Outputs

Pawan Khowal – Join Outputs

Please leave a comment if you need solution to the above puzzle

Keep Learning

Advertisements