Tuesday 10 February 2009

Visual Representation of SQL Joins + Set Notations

Throwing some Gyan on Sql Join/Set theory after reading an article on
Sql Joins in codeproject.

[Thanks to good old shool days set theory lectures.]

'A' & 'B' are two sets,

1) A n B = Inner Join ( 'n' -- Intersection)

2) A u (A n B) = left join ( 'u' -- union )

3) (A n B) u B = right join

4) A u B u (A n B) = outer join

5) A - B = Left join excluding inner join or relative complement

6) B - A = right join excluding inner join

7) (A - B) U (B - A) = outer join excluding inner join.

[Note:- Given the fact that Sql Joins are popular tech. interview question,you can use above stuff to impress your interviewer.I hope above set notions will help you to answer Sql Join Q?'s in a generic way rather than explaining using 'Table1' , 'Table2' etc.... ]