The 17th chapter: Combination Query
P114
Select vend_id, prod_id,prod_price from products where Prod_price <=5;
Select vend_id, prod_id,prod_price from Products where vend_id in (1001,1002);
P115 combination of the above two statements.
Select vend_id, prod_id,prod_price from products where Prod_price <=5 Union select vend_id, Prod_id,prod_price from PR Oducts where vend_id in (1001,1002); #可以看到, the result is the same as the result of the above two statements (minus duplicates), quite two programs using the OR statement #
P116 Union must have more than one SELECT statement, and each column contains the same column, expression, or aggregation function (#不懂这句话, I feel the column name is the same, solve??? #)
In addition, the Union automatically de-processes the results. If you don't need to go heavy, then use UNION ALL
Select vend_id, prod_id,prod_price from products where Prod_price <=5 UNION ALL Select vend_id, Prod_id,prod_price fro M products where vend_id in (1001,1002);
P117
Select vend_id, prod_id,prod_price from products where Prod_price <=5 UNION ALL Select vend_id, Prod_id,prod_price fro M products where vend_id in (1001,1002) order by Vend_id,prod_price; #使用union组合查询时, you can only use order by to pose, and the order by can only appear after the last SELECT statement #
"MySQL Must know" study _ the 17th chapter _20180807_ Huan