首页 > 数据库技术 > 详细

MySQL 连接

时间:2019-10-08 12:12:48      阅读:66      评论:0      收藏:0      [点我收藏+]

子查询并不总是查询的最优性能。

连接多个表

使用连接的方式来实现,子查询实现的 返回订购产品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;

 

两个表之间的关系是FROM子句的组成部分,以INNER JOIN指定。在使用这种语法时,联结条件用特定的ON子句而不是WHERE子句给出。传递给ON的实际条件与传递给WHERE的相同。

MySQL 连接

原文:https://www.cnblogs.com/bowenqianngzhibushiwo/p/11634293.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!