多张表进行连接查询步骤,
1、先找到需要查询的表
2、分开查找连接条件,多个连接条件使用and
连接
3、 查询条件
,直接跟在where的连接条件后面
,用and
连接
示例1:1、查询“研发部”所有员工的信息及工资等级
涉及的表:emp(员工表)、salgrade(薪资等级表)、dept(部门表)
连接条件:emp.salary between salgrade.losal and salgrade.hisal
emp.dept_id=dept.id
查询条件:dept.name="研发部"
sql第一步:写出连接条件
select * from emp e,dept d,salgrade s where emp.dept_id=dept.id and (e.salary between s.losal and s.hisal)
第二部:再加上查询条件
select * from emp e,dept d,salgrade s where emp.dept_id=dept.id and (e.salary between s.losal and s.hisal )and d.name="研发部"
第三部:完善查询信息
select e.*,s.grade from emp e,dept d,salgrade s where emp.dept_id=dept.id and ((e.salary between s.losal and s.hisal )and d.name="研发部