子查询并不总是查询的最优性能。
连接多个表
使用连接的方式来实现,子查询实现的 返回订购产品TNT2的客户列表
子查询:
select cust_Id,cust_name from customers where cust_id in(select order_num form orders where order_num in(select order_num from orderItems where prod_Id=‘TNT2‘));
连接:
select cust_id ,cust_name
from customers, orders,orderitems
where customers.cust_id=orders.cust_id
and orders.order_num=orderitems.ordernum
and prod_Id=‘TNT2;
连接是SQL语句最强大的功能。
内连接
inner join 。。。on
select vend_name, prod_name,prod_price
from vendors INNER JOIN products
on venders.vend_id=products.vend_id;
原文:https://www.cnblogs.com/bowenqianngzhibushiwo/p/11634293.html