子查询(嵌套式查询)
一条搜索语句他的过滤条件来源于另一个搜索语句的select结果
select cust_name,cust_contact from customers
where cust_id in (select cust_id
from orders
where order_num IN (select order_num
from orderitems
where prod_id = 'TNT2'));
计算字段使用子查询
注意:子查询时对于不同表的字段一定要限定是哪个表中的(通过表名.字段名)
select cust_id,cust_name,(select count(*)
from orders
where orders.cust_id = customers.cust_id) as orders)
from customers order by cust_name;