《08从多个表中获取数据》-课件设计(公开).pptVIP

《08从多个表中获取数据》-课件设计(公开).ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
目标 完成本节课的学习后,应当达到如下目标: 写出能从多个等连接或者非等连接的表中取出数据的SQL语句。 使用外连接来查找数据。 写出一个表与其自身连接的SQL语句。 从多个表中获取数据 什么是连接? 用一个连接来从多个表中获取数据. 在Where子句中书写连接的条件. 如果某个列的名字在多个表中出现了,那么需要在列的名字前面加上表名作为前缀. 笛卡尔积 以笛卡尔积连接的表具有下列特征: 连接条件被忽略。 第一个表中的所有的行与第二个表中的所有行相连接。 如果在WHERE子句中加入条件,那么可以避免笛卡尔积. 产生一个笛卡尔积 连接的类型 什么是等连接? 用等连接获取纪录 限定不明确的列名 用表名作为前缀来限定在多个表中都出现的列名字. 利用表的前缀可以提高性能. 使用不同的别名来标志在不同表中的相同的名字。 用 AND操作符增加查询条件 使用表的别名 使用的表的别名来简化查询 连接多个表 非等连接 用非等连接查询记录 外连接 外连接 可以用外连接来查出在一个表中,不匹配连接条件的行. 外连接的符号是: (+). 使用外连接 自连接 表与自身连接 总结 本课程版权归北风网所有 欢迎访问我们的官方网站 Data from Multiple Tables Sometimes you need to use data from more than one table. In the slide example, the report displays data from two separate tables. EMPNO exists in the EMP table. DEPTNO exists in both the EMP and DEPT tables. LOC exists in the DEPT table. To produce the report, you need to link EMP and DEPT tables and access data from both of them. Instructor Note In the slide, the DEPTNO column can come from either the EMP or the DEPT table. Defining Joins When data from more than one table in the database is required, a join condition is used. Rows in one table can be joined to rows in another table according to common values existing in corresponding columns, that is, usually primary and foreign key columns. To display data from two or more related tables, write a simple join condition in the WHERE clause. In the syntax: table1.column denotes the table and column from which data is retrieved table1.column1 = is the condition that joins (or relates) the tables together table2.column2 Guidelines When writing a SELECT statement that joins tables, precede the column name with the table name for clarity and to enhance database access. If the same column name appears in more than one table, the column name must be prefixed with the table name. To join n tables together, you need a minimum of (n-1) join conditions. Therefore, to join four tables, a minimum of three joins are required. This rule may not apply if your table has a c

您可能关注的文档

文档评论(0)

花好月圆 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档