数据库各种join的区别

1.数据库join的类型主要分为left join、right join、inner join

2.left join 表示左边的表为主表,右边连接的表可以为NULL

如:

select a.id,a.name,b.name,b.city from user a left join liveregion b on a.cityId = b.id;

此处查询就可能出现a表的cityId为NULL时也能b表数据又为NULL的情况,即代表a表数据可以出现NULL

3.right join 表示右边的表为主表,左边连接的表可以为NULL

同理如上。

4.inner join 内连接 表示两个表均相关联的信息。

本博客参见:http://blog.csdn.net/shadowyelling/article/details/7684714

猜你喜欢

转载自youngstream.iteye.com/blog/2257879