MySQL社区

标题: 对MySQL中join语句(连接)语法总结 [打印本页]

作者: kider    时间: 2007-9-3 12:27
标题: 对MySQL中join语句(连接)语法总结
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的语法被扩展了。
作者: mysqlkumao    时间: 2008-4-10 11:13
MySQL不支持全连接的吧!
作者: kider    时间: 2008-9-4 11:05
原帖由 mysqlkumao 于 2008-4-10 11:13 发表
MySQL不支持全连接的吧!


说的对,说是未来的版本会支持。

但现在看来,目前的版本5.1和6.0版本中,SQL语法还是暂不支持全连接的。




欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2