第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. gentoo freemind 安装设置

    安装 freemind 之后,感觉菜单上面的字体比较模糊,通过设置 tools --> preference 中的 defaults --> default fonts 里面 的 defa ...

  2. RMI(远程方法调用)入门

    这两篇可以入门 http://www.cnblogs.com/ninahan0419/archive/2009/06/25/javarmi.html http://www.cnblogs.com/wx ...

  3. 《面向对象程序设计(Java)》第四周学习总结

    第一部分 第四章部分理论知识 1.面向对象程序设计概述:java是完全面向对象的,必须熟悉OOP才能编写java程序. 类:由类构造对象的过程称为创建类的实例. 封装:封装是将数据和行为组合在一个包中 ...

  4. leetcode309

    使用动态规划,下面的代码可以通过210个测试,最后1个(第211个)会超时.说明思路是正确的,但是其中有一些是无效的计算. class Solution { public: int maxProfit ...

  5. pyqt5 -——介绍及和pycharm的环境搭建

    pyqt5简介: yQt5的类存在与如下模块当中: ● QtCore ● QtGui ● QtWidgets ● QtMultimedia ● QtBluetooth ● QtNetwork ● Qt ...

  6. Django01-Django基础

    一.什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统.对于所有的Web应用,本质上其实就是一个socket服 ...

  7. 我尼玛,二半夜的说中photo.src病毒了。

    大半夜手机预警,中病毒了,我感觉也没啥东西呀.一个破小网站,别人黑我干啥. 登上服务器去一看,我滴个乖乖,photo.src病毒.服务器里面显示是一个背景桌面应用程序, 打算直接从文件夹删除,但是正在 ...

  8. 爬虫 1 requests 、beautifulsoup

    1.requests 1.method 提交方式:post.get.put.delete.options.head.patch 2.url 访问地址 3.params 在url中传递的参数,GET p ...

  9. idea导入eclipse项目的配置

    idea导入eclipse项目需要的配置 1.配置jdk,这两处选择一样就可以,也可以根据自己需求选择,上边的比下边的版本高就行 2.这里会默认和配置jdk一样 3.添加lib依赖,选择到项目的lib ...

  10. [Java核心技术]第四章-对象与类(4.1-4.6总结)

    4.1面向对象程序设计概述 OOP(面向对象编程Object Oriented Programming) OOP中数据第一位,算法第二位. 类 封装:关键在于不能让其他方法直接访问类的实例域,程序仅通 ...