1. Join / inner join 内连接
只获得2张表相同的内容(交集)
例如: 表1 获取全部数据,表2获取满足条件的 id列 数据。
ON 条件==== 俩表id相同
select * from tb_user a JOIN (select id from tb_user where updated>'2015-07-30 17:48:33' order By id DESC LIMIT 0,3)b ON a.id=b.id
-- where a.id=36
表a 获取全部数据:

表b 数据如下:

执行内连接语句后:(先获取的是表a全部数据,再根据表b的数据,取出相同 id 的数据)

2. Left join 左连接
获取表1的所有数据列数据以及表2满足条件的数据列,没有的则空
select * from tb_user a LEFT JOIN (select id from tb_user where updated>'2015-07-30 17:48:33' order By id DESC LIMIT 0,3)b ON a.id=b.id

3. Right join 右连接
获取表2的所有数据列数据以及表1满足条件的数据列,没有的则空
select * from tb_user a RIGHT JOIN (select id from tb_user where updated>'2015-07-30 17:48:33' order By id DESC LIMIT 0,3)b ON a.id=b.id

网友评论