Mysql多表查询实践
一、目的
1、掌握多表连接的基本方法
2、学会使用SQL命令进行多表查询操作
3、学会使用SQL命令进行子查询操作
二、内容
用于企业管理的员工管理数据库,数据库名为YGGL,包含员工信息表Employees、部门信息表Departments、员工薪水情况表Salary ,各表数据如下。
对YGGL数据库完成以下查询。
1、 查询“伍容华”的基本情况和所工作的部门名称
select employees.*,departments.部门名称
from employees,departments
where employees.员工部门号=departments.部门编号 and employees.姓名='伍容华';
2、 查询财务部、研发部、市场部的员工信息。
select departments.部门名称,employees.*
from departments,employees
where employees.员工部门号=departments.部门编号 and departments.部门名称 in ('财务部','研发部','市场部'