Pages

Tuesday, 19 February 2013

SQL SERVER – Introduction to JOINs – Basic of JOINs

RIGHT OUTER JOIN

This join returns all the rows from the right table in conjunction with the matching rows from the left table. If there are no columns matching in the left table, it returns NULL values.



SELECT t1.*,t2.*
FROM Table1 t1
RIGHT JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t1.ID IS NULL

SQL SERVER – Introduction to JOINs – Basic of JOINs

CROSS JOIN

This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.


SELECT t1.*,t2.*
FROM Table1 t1
CROSS JOIN Table2 t2