《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的产品数目总值 ...
随机推荐
- js 一些方法
1.js去除字符串前后的空格 function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } 2.js打乱数组的顺 ...
- leetcode每日刷题计划-简单篇day1
orzorz开始刷题 争取坚持每周平均下来简单题一天能做两道题吧 非常简单的题奇奇怪怪的错误orz越不做越菜 Num 7 整数反转 Reverse Integer 刚开始多给了一个变量来回折腾占地方, ...
- Jquery对表格的一些简单应用 查询&即时匹配&点击高亮等
代码如下(暂时没有用原生js实现): <!DOCTYPE html> <html lang="en"> <head> <meta char ...
- Python协程、异步IO
本节内容 Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko SS ...
- LeetCode OJ 129. Sum Root to Leaf Numbers
题目 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a num ...
- es6之更优雅的条件语句
在使用JavaScript时,条件判断是经常会用到的,一些简单的判断条件还可以接受,当遇到比较复杂多重条件时就比较恶心了.这里使用es6的小技巧使判断更优雅. 1.使用 Arrary.includes ...
- Xshell 6安装与使用教程
随着xshell5出现评估期已过的问题,发现好多人不知道怎么下载免费版的Xshell,在这里我将详细告诉大家如何下载和安装最新的Xshell6远程管理工具. Xshell安装 1.进入xshell英文 ...
- maven安装cucumber的pom文件设置
1.在windows上安装maven 2.安装Eclipse 3.在eclipse上面配置maven,并新建一个maven项目 4.在maven项目里面找到pom.xml,编辑pom.xml,之后点击 ...
- Mysql 关键字
ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH BY CALL CASCADE C ...
- APIcloud微信支付和支付宝支付(方案2,主要在后台进行)
支付宝代码 var aliPay = api.require('aliPay'); api.ajax({ url: yuming+'index.php/api/Alipay/getOrder', me ...