Learn SQL Join,Inner Join, Outer Join

来源:互联网 发布:企业域名代备案 编辑:程序博客网 时间:2024/05/16 18:38
For Example:

Table A have 12( 8+4) entries, 8 entries have valid relation with B
Table B have 80(77+3) entries , 77 entries have valid relation with A.

then the return amount of join is :
cross join : 12*80
inner join : 77
full outer join : 77+4+3
left outer join: 77 + 4
right outrer join: 77 + 3


INNER Join code as the following:

Select * from A a, B b where a.categoryID = b.categoryID;
equals:
Select * from A a inner join B b on a.categoryID = b.categoryID;

OUTER Join code as the following

select * from A a full(left/right) outer  join B b  on a on a.categoryID = b.categoryID;

left/right outer join claus specific  for MSSQL:
Select * from A a, B b where a.categoryID  *=    bcategoryID;
elect * from A a, B b where a.categoryID      =*   b.categoryID;

left/right outer join claus specific for Oracle:
Select * from A a, B b where a.categoryID       =   b.categoryID(+);
Select * from A a, B b where a.categoryID (+) =  b.categoryID;


Good Resources:
http://www.w3schools.com/sql/sql_join.asp
http://www.techonthenet.com/sql/joins.htm