"MySQL Must know" study _ the 14th chapter _20180806_ Huan

Source: Internet
Author: User

The 14th chapter: using sub-queries.

A subquery is a condition that is embedded in other queries, quite other than the select query.

P91

Select Order_num from where prod_id= ' tnt2 '; The =tnt2 of the #检索条件为prod_id order_num#

Select cust_id from the orders where Order_num in (20005,20007); #检索满足条件 Order_num in the range (20005,20007) of cust_id#

Select cust_id from Orders where Order_num in (select Order_num from orderitems where prod_id = ' tnt2 '); #检索 meet the conditions:///In the table OrderItems to meet the Prod_id=tnt2 order_num,orderitems.order_num =orders.order_num//This part of the Order_ The cust_id # # #实际上 that num corresponds to in orders is the combination of the above two statements #

P92

Select Cust_name,cust_contact from Customers where cust_id in (10001,10004); Within the #检索表customers满足客户Id在范围 (10001,10004), the corresponding Cust_name,cust_contact #

Select Cust_name,cust_contact from Customers where cust_id in (select cust_id from Orders where Cust_num in (select Cust_n Um from orderitems where prod_id = ' tnt2 '); #镶嵌了两个子查询, starting with the conditions of the innermost brackets #

"MySQL Must know" study _ the 14th chapter _20180806_ Huan

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.