MySQL的union关键字⽤法
union关键字的⽤法很简单就是给每条lect查询语句之间加上union关键字,那么他们的查询结果集就会都查询处理,union关键字也就意味着相当于“且”的意思。
测试数据:使⽤之前的MySQL的聚集函数的那⼀个测试表
轻音乐歌曲查看下⾯两个lect查询:
lect * from gather where price <5;
lect * from gather where price >3;
抖音的危害因为都是同⼀张表,这⾥⽤*来代替,如果不同的表来测试union时,需要查询相同的字段什么的未来
lect *
耶律洪基
from gather
where price < 5
union
lect *
from gather
where price > 3;
我们会发现使⽤union时查询的数据少于两个分别查询之和,那些重复的查询结果只返回⼀个。如果想要重复的查询结果也要显⽰,那么就
需要使⽤ union all
lect *
from gather
where price < 5
union all小保姆
lect *
奇妙近义词from gather
where price > 3;
优美文段100字
对于使⽤union组合查询的结果集要排序时,是能使⽤⼀个order by语句。⽽且它必须要放在最后⼀个lect语句后⾯。lect *
颈下淋巴结肿大from gather
where price < 5
union
lect *
from gather
where price > 3
order by price;