|
1.Inner join(内连接)
select first_name,surname,value from a ,b where id=customer;
= select first_name,surname,value a inner join b on id=customer;
2.Left join(左连接)
列出左表中所有的记录,包括没有和右表中匹配到的记录。
3.Right join(右连接)
列出右表中所有的记录,包括没有和左表中匹配到的记录。
4.Full outer join(全外连接)
是左连接和右连接的全集。- 未来支持
5.Natural join(自然连接)
select first_name,surname,value from a ,b where a.id=b.id;
= select first_name,surname,value a natural join b;
即:相同的列(只要名字相同就可以,类型不同也可以),using关键字可以省略。也可以从多个相同的列中只选出其中需要的列匹配。
也分左、右自然连接 natural left join /natural right join
-----------------------------------------
MySQL支持以下JOIN语法:
join_table:
table_reference [INNER | CROSS] JOIN table_factor [join_condition]
| table_reference STRAIGHT_JOIN table_factor
| table_reference STRAIGHT_JOIN table_factor ON condition
| table_reference LEFT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [LEFT [OUTER]] JOIN table_factor
| table_reference RIGHT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [RIGHT [OUTER]] JOIN table_factor
join_condition:
ON conditional_expr
| USING (column_list) | 与SQL标准相比,table_factor的语法被扩展了。 |
|