Thursday, September 11, 2008

[SQL] Join Tables

Student:

Book:
ID Name
SID Book
1 feng
1 abc
2 yong
null def





[Inner] Join


ID Name SID Book
1 feng 1 abc





Left [Outer] Join: 左表所有行, 右表没有匹配行则均为null
ID Name SID Book
1 feng 1 abc
2 yong null null





Right [Outer] Join


ID Name SID Book
1 feng 1 abc
null null null def





Full [Outer] Join


ID Name SID Book
1 feng 1 abc
2 yong null null
null null null def





CROSS JOIN


ID Name SID Book
1 feng 1 abc
1 feng null def
2 yong 1 abc
2 yong null def

No comments: