码迷,mamicode.com
首页 > 数据库 > 详细

《mysql必知必会》学习_第14章_20180806_欢

时间:2018-08-06 14:42:28      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:nbsp   http   开始   .com   客户   ems   条件   custom   img   

第14章:使用子查询。

子查询是镶嵌在其他查询里面,相当其他的select查询的条件来。

P91 

select order_num from where prod_id=‘tnt2‘;   #检索条件为prod_id=tnt2的order_num#

select cust_id from orders where order_num in (20005,20007);    #检索满足条件 order_num在范围(20005,20007)的cust_id#

技术分享图片

select cust_id from orders where order_num in (select order_num from orderitems where prod_id =‘tnt2‘ );  #检索 满足条件:///在表orderitems中满足prod_id=tnt2 的order_num,orderitems.order_num =orders.order_num  /// 这部分的order_num在orders中对应的cust_id # ##实际上,就是上面的两个语句组合而成的##

技术分享图片

 

 P92

select cust_name,cust_contact from customers where cust_id in (10001,10004); #检索表customers满足客户Id在范围(10001,10004)内,对应的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_num from orderitems where prod_id =‘tnt2‘) ); #镶嵌了两个子查询,从最里面的括号的条件开始运行#

技术分享图片

 

《mysql必知必会》学习_第14章_20180806_欢

标签:nbsp   http   开始   .com   客户   ems   条件   custom   img   

原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9429788.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!