MySQL复习04-联合查询、DML

联合查询、DML

1.UNION、OR

1.UNION会合并相同的结果。UNION ALL则不会。
2.多条语句查询列数要相同

# 查询部门编号>90或邮箱包含a的员工信息。
# 普通查询方法
select * from employees where email like '%a%' or department_id> 90;
# 联合查询
select * from employees where email like '%a%'
union
select * from employees where department_id > 90;

2.DML

数据库操作语言

insert
update
delete
truncate
// 允许多行插入。
insert into beauty(id, name,phone)
values(11,'aa','123123'),(15,'bb','123123'),(14,'cc',null);
update beauty set phone = '13489156486'
where id=5;
// 允许多表更新,但是有不少注意事项,不建议。比如:不能有聚合函数。
update boy
inner join gril
on boy.id = girl.bf_id
set girl.phone = '16841534'
where boy.name = '法外狂徒';
# 删除张三和女朋友的信息。
delete g,b from girl g
inner join boy b
on g.bf_id = b.id
where b.name = '张三';
# 删除张三的女朋友的信息。
delete g from girl g
inner join boy b
on g.bf_id = b.id
where b.name = '张三';

庄周晓梦迷蝴蝶,望帝春心托杜鹃。——李商隐

猜你喜欢

转载自blog.csdn.net/weixin_37627774/article/details/108582707