不愿意做出改变 ≈ 坐吃等死!!

SQL联结union/intersect/except总结

上一篇 / 下一篇  2017-03-25 17:36:26 / 个人分类:数据库

1. 多个查询联结

代码:
select * from table1 where xxx
select * from table2 where yyy;

结果:
将两次的查询联结,且去重复

2. 多个查询联结[不去重]

代码:
select * from table1 where xxx
union all
select * from table2 where yyy;

结果:
将两次的查询联结,但不去重

3. 在table1存在但table2不存在的联结查询


代码:
select * from table1 where xxx
select * from table2 where yyy;

结果:
将条件1的结果排除掉条件2的结果查询出来

4. 查询两表共有的行

代码:
select * from table1 where xxx
select * from table2 where yyy;

结果:
将满足条件1且满足条件2的行查询出来


备注:上面4种查询必须满足两次或者多次查询的数据结构一致,才能联结!


欢迎交流指正!


TAG: union except intersect unionall sql联结 联结查询 sql查询

 

评分:0

我来说两句

Open Toolbar