MySQL多表连接和分页查询

一、外链接(用on子句给定连接条件)

  • left outer join 左外连接
  • right outer join 右外连接
  • union:可以将两个查询结果集合并,返回的行都是唯一的,如同对整个结果集合使用了
    DISTINCT。
  • union all:只是简单的将两个结果合并后就返回。这样,如果返回的两个结果集中有重复的数据,
    那么返回的结果集就会包含重复的数据了。
select e.last_name,d.address from emp e,dept d where e.dept_id = d.dept_id; 等值连接
select * from emp cross join dept; 交叉连接
select * from emp natural join dept; 自然连接
select * from emp join dept using(dept_id); 选定条件的自然连接
select * from emp inner join dept on emp.dept_id = dept.dept_id; 内连接
select * from emp inner join dept using(dept_id); 内连接

二、分页查询
语法:
select 投影列 from 表名 where  条件 order by limit 开始位置,查询数量 。

语法:
select 投影列 from 表名 where  条件 order by limit 查询数量 offset 开始位置。

posted @ 2021-10-20 23:46  白_沙  阅读(1531)  评论(0编辑  收藏  举报