MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 9007|回复: 4
打印 上一主题 下一主题

[例子类] 对MySQL中join语句(连接)语法总结

[复制链接]
跳转到指定楼层
1#
发表于 2007-9-3 12:27:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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的语法被扩展了。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
发表于 2008-4-10 11:13:28 | 只看该作者
MySQL不支持全连接的吧!
3#
 楼主| 发表于 2008-9-4 11:05:44 | 只看该作者
原帖由 mysqlkumao 于 2008-4-10 11:13 发表
MySQL不支持全连接的吧!


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

但现在看来,目前的版本5.1和6.0版本中,SQL语法还是暂不支持全连接的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-4-26 16:16 , Processed in 0.065185 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表