Home > Database > Mysql Tutorial > SQL关联操作(查询与更新)_MySQL

SQL关联操作(查询与更新)_MySQL

PHP中文网
Release: 2016-05-27 19:11:43
Original
1652 people have browsed it

sql的除了关联查询,还可以关联更新删除等,有时可以一条sql搞定数据移植, 避免写存储过程时。

以下列举了sql的各种级联操作场景。 

主表:部门表-dept(dept_id,dname,enum)

 

从表:员工表-emp (emp_id , ename , sal,dept_id)

 

//以下是oracle的sql语法

 

1,关联查询

 

场景:查询所有员工的部门名称

 

2,关联更新

 

场景:更新部门表的人数enum 

update dept d set d.enum = 
 (select count(*) from emp ewhere e.dept_id=d.dept_id );
Copy after login

 

3,关联子查询

 

场景a:哪些员工的工资-sal 比本部门的平均工资高 

 

场景b:查出没有员工的部门 

 

4,关联删除

 

场景:删除没有员工的部门

以上就是SQL关联操作(查询与更新)_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template