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