《mysql必知必会》学习_第15章_20180806_欢
第15章:联结表
P98
外键:外键为某个表的一列A,同时这一列包含另一个表的主键值B(B属于A,等于或者小于的关系)
P99
select vend_name,prod_name,prod_price from vendors,products where vendors.vend_id =products.vend_id order by vend_name,prod_name;
# 选择的vend_name,prod_name只是在products表格中出现,所以无须指明是哪个表,这个的语句的条件是vend_id=products.vend_id ,排列顺序是先遵循vend_name的字母排列,若vend_name排列无效或重复,再遵循prod_name的排列。# ##当要检索的几个列出现在几个表中,又没有其他的限制条件,也没有说明读取的列是在同一个表,那得到的结果应该就会呈现笛卡儿积(##是我自己的观点)##

P101 笛卡儿积
select vend_name,prod_name,prod_price from vendors,products order by vend_name,prod_name ; #没有联结关系的表返回的结果是笛卡儿积,行数=第一个表的行数*第二个表的行数# ##没有限定条件,而且要检索到的列出现在两个表格中## ###下面没截图到###
P103 内部联结
select vend_name,prod_name,prod_price from vendors inner join products on vendors.vend_id=products.vend_id ; #这条语句和(select vend_name,prod_name,prod_price from vendors,products where vendors.vend_id =products.vend_id order by vend_name,prod_name; )表示的意思一样#

P104 联结多个表,能联结的表的数目是没有影响的,列出表,定义它们之间的关系
select prod_name,vend_name,prod_price,quantity from orderitems,products ,vendors where products.vend_id=vendors.vend_id and orderitems.prod_id=products.prod_id and order_num=20005; #多个表进行联结,原理和前面两个表是一样的#

P105
select cust_name,cust_contact from customers where cust_id in (select cust_id from orders where order_num in (select cust_id from orders where order_num in (select order_num from orderitems where prod_id ='TNT2')) ;
select cust_name, cust_contact from customers,orders,orderitems where customers.cust_id=orders.cust_id and orderitems.order_num =orders.order_num and prod_id='TNT2';
#前面的两语句联结的数据库,表达的意思一样#

理解好关联的表之间的关系就可以了
《mysql必知必会》学习_第15章_20180806_欢的更多相关文章
- 《mysql必知必会》学习_第14章_20180806_欢
第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2'; #检索条件 ...
- 《mysql必知必会》学习_第18章_20180807_欢
第18章 全文本搜索 P121 #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id int NOT ...
- 《mysql必知必会》学习_第五章_20180730_欢
使用的工具是wamp的Mysql. P29 select prod_name from products; #在表products中选列prod_name,顺寻不是纯粹的随机,但是没有说明排列顺序, ...
- 《mysql必知必会》学习_第22章_20180809_欢
第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果.并不是说在数据库里面真的存在这个表,但是是真的存在这些数据. select cust_name,cust_contact from c ...
- 《mysql必知必会》学习_第20章_20180809_欢
第20章:更新和删除数据 P140 update customers set_emails='elmer@fudd.com' where cust_id=10005; 更新多个列,用逗号隔开.注意被指 ...
- 《mysql必知必会》学习_第19章_20180809_欢
第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA', ...
- 《mysql必知必会》学习_第17章_20180807_欢
第17章:组合查询 P114 select vend_id ,prod_id,prod_price from products where prod_price <=5 ; select ven ...
- 《mysql必知必会》学习_第16章_20180807_欢
第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from ven ...
- 《mysql必知必会》学习_第13章_20180803_欢
第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值 ...
随机推荐
- 关于h5使用bpmn.js
bpmn.js网站地址:https://bpmn.io/toolkit/bpmn-js/ bpmnjs是一款工作流绘制框架,遵循了bpmn2.0规范,实现从前台绘制工作流到后台执行的效果. 图示: 但 ...
- 0初识Linux
今天三八妇女节,Linux就该这么学,开课第一天.信心满满,激动,期待,要努力了.(博客为预习写的,今天又做了更新.) Linux第一印象就是黑色背景屏幕,上面还有好多代码,敲的一手好的命令操控着 ...
- java 流转换BASE64的一些问题
java 转换BASE64过程中,出现很多结尾为空的问题!暂时不清楚为什么会这样- ``` java //根据url地址转换成BASE64 public static String getURLIma ...
- Linux命令:pwd
打印当前目录的完全路径. -L 打印路径包含符合路径 -P 打印路径不含符合路径. -LP,可能打印的不同,取决于你对进入当前目录的方式是通过符号链接进入,还是物理目录进入.如果是符号链接进入,则-L ...
- MySQL统计信息以及执行计划预估方式初探
数据库中的统计信息在不同(精确)程度上描述了表中数据的分布情况,执行计划通过统计信息获取符合查询条件的数据大小(行数),来指导执行计划的生成.在以Oracle和SQLServer为代表的商业数据库,和 ...
- jquery之过滤filter,not
<body> <h1>欢迎来到我的主页</h1> <p>我是唐老鸭</p> <p class="intro"> ...
- 数据库中多对多关系的处理 User---Role
--一个用户可以担任多个角色,如user1既是调度员又是分拣员--一个角色可以被多个用户担任,如user1是调度员,user2也是调度员--用户和角色之间的对应关系为多对多,所以会产生中间表 t_us ...
- DOM 扩展
1.选择符API,selectors API 可以使用CSS选择符匹配查找节点 1) querySelector(selector),接受一个CSS选择符,返回调用该函数的节点后代中第一个匹配的元素 ...
- 语义分割之Dual Attention Network for Scene Segmentation
Dual Attention Network for Scene Segmentation 在本文中,我们通过 基于自我约束机制捕获丰富的上下文依赖关系来解决场景分割任务. 与之前通过多尺 ...
- CentOS 特殊变量($0、$1、$2、 $?、 $# 、$@、 $*)
名称 说明 $0 脚本名称 $1-9 脚本执行时的参数1到参数9 $? 脚本的返回值 $# 脚本执行时,输入的参数的个数 $@ 输入的参数的具体内容(将输入的参数作为一个多个对象,即是所有参数的一个列 ...