"MySQL Must know" study _ the 17th chapter _20180807_ Huan

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.