SQL is required. note Chapter 1 use subquery. SQL is required.
11.1 subquery
Query any SQL statement is a query. However, this term generally refers to a SELECT statement.
SQL also allows you to create subqueries, that is, queries nested in other queries.
11.2 Filter Using subqueries
SELECT cust_idFROM OrdersWHERE order_num IN (SELECT order_num FROM OrderItems WHERE prod_id = 'rga01 ');
In SELECT statements, subqueries are always processed from the inside out.
SELECT cust_name, cust_contactFROM CustomersWHERE cust_id IN (SELECT cust_id FROM Orders WHERE order_num IN (SELECT order_num FROM OrderItems WHERE prod_id = 'rga01 '));
It can only be a single column: SELECT statements used as subqueries can only query a single column. An error is returned when you attempt to retrieve multiple columns.
11.3 use subquery as a calculated Field
To execute COUNT (*) for each customer, it should be used as a subquery.
SELECT cust_name, cust_state, (select count (*) FROM Orders WHERE Orders. cust_id = MERs. cust_id) AS ordersFROM CustomersORDER BY cust_name;