1.创建组合查询
select vend_id,prod_id,prod_price from products where prod_price<=5; //单价小于五的商品 union select vend_id,prod_id,prod_price from products where vend_id in(1001,1002); // 商品id在10001,10002
2.union规则
3.包含或取消重复的行
包含重复的行
select vend_id,prod_id,prod_price from products where prod_price<=5; //单价小于五的商品 union all select vend_id,prod_id,prod_price from products where vend_id in(1001,1002); // 商品id在10001,10002
取消重复的行
select vend_id,prod_id,prod_price from products where prod_price<=5; //单价小于五的商品 union select vend_id,prod_id,prod_price from products where vend_id in(1001,1002); // 商品id在10001,10002
4.对组合查询结果排序
select vend_id,prod_id,prod_price from products where prod_price<=5; //单价小于五的商品 union select vend_id,prod_id,prod_price from products where vend_id in(1001,1002) order by prod_price desc; // 商品id在10001,10002
注意order by只能在最后排序
感谢观看