select * from student s where s.stuName in(“张三”,“李四”,“王五”)and s.age>18
优化后的sql:
select * from student s where s.stuName=“张三” and s.age>18 and s.sex=‘男’
union all
select * from student s where s.stuName=“李四” and s.age>18 and s.sex=‘男’
union all
select * from student s where s.stuName=“王五” and s.age>18

union和union all的用法

将两个select的结果作为一个整体显示出来。

满足条件:

1、两个select查询的列的数量必须相同;

2、每个列的数据类型需要相似;

区别

union all是将两个select语句的结果求并集。 union是将union all的结果下再去除重复数据

世界上最美的风景,是自己努力的模样