第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_欢的更多相关文章

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

    第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2';   #检索条件 ...

  2. 《mysql必知必会》学习_第18章_20180807_欢

    第18章 全文本搜索 P121  #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id  int   NOT ...

  3. 《mysql必知必会》学习_第五章_20180730_欢

    使用的工具是wamp的Mysql. P29 select prod_name from products;  #在表products中选列prod_name,顺寻不是纯粹的随机,但是没有说明排列顺序, ...

  4. 《mysql必知必会》学习_第22章_20180809_欢

    第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果.并不是说在数据库里面真的存在这个表,但是是真的存在这些数据. select cust_name,cust_contact from c ...

  5. 《mysql必知必会》学习_第20章_20180809_欢

    第20章:更新和删除数据 P140 update customers set_emails='elmer@fudd.com' where cust_id=10005; 更新多个列,用逗号隔开.注意被指 ...

  6. 《mysql必知必会》学习_第19章_20180809_欢

    第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA', ...

  7. 《mysql必知必会》学习_第17章_20180807_欢

    第17章:组合查询 P114 select vend_id ,prod_id,prod_price from products where prod_price <=5 ; select ven ...

  8. 《mysql必知必会》学习_第16章_20180807_欢

    第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from ven ...

  9. 《mysql必知必会》学习_第13章_20180803_欢

    第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值 ...

随机推荐

  1. kubernets网络模式

    参考:https://www.kubernetes.org.cn/2059.html

  2. 【笔记】range函数在py3里面的处理及numpy库效率比较【原创】

    今天看了一下,numpy数组操作其中一段代码,主要是测试用纯python和numpy之间的性能问题 在py2环境下,代码如下: def pysum(n): a = range(n) b = range ...

  3. <记录> Razor引擎&视图布局

    标识符 @ Razor支持HTML和C#代码混编,意味着可以在HTML中随意输出变量 基本使用方法 直接@后面跟变量(当遇到 HTML标签 .空格.换行符等特殊符号时 便认为@之后到特殊符号前为变量名 ...

  4. linux显示历史命令history

    history history//显示历史命令

  5. test case VS test scenario

    ---恢复内容开始--- 1. test case: how to test --如何测试 test scenario: what to  be tested  --测试什么 2. test scen ...

  6. http://www.36dsj.com/archives/46131

    https://docs.growingio.com/Developer%20Document.html https://youdata.163.com/dash/39706/editor?pid=7 ...

  7. MySql/Oracle树形结构查询

    Oracle树形结构递归查询 在Oracle中,对于树形查询可以使用start with ... connect by select * from treeTable start with id='1 ...

  8. DB2(Procedure)存储过程遍历循环!

    有时候一些复杂的业务逻辑将要通过存储过程的循环语句进行处理;以下列出2种DB2存储过程的循环语句,方便以后的查看并使用! 推荐第一种方式的使用,最大的优点就是比较直观;在需要操作很多字段的情况下,不需 ...

  9. 商品批量删除(mybatis中集合的使用)

    <!-- 根据主键批量删除 --> <delete id="deleteByKeys"> DELETE FROM product WHERE id in & ...

  10. elk中es集群web管理工具cerebro

    cerebo是kopf在es5上的替代者 安装es虽然不能再root下运行,但是cerebro 可以 run as root is ok wget https://github.com/lmeneze ...