zoukankan      html  css  js  c++  java
  • 第十二章 联结表

    第十二章 联结表

    为什么要用联结表?

    1. 每个表应该内容应该相互独立,方便修改以及扩展

    2. 通过联结查看两个表的混合数据

    1. 创建联结

    select vend_name,prod_name,prod_price from vendors,products where vendors.vend_id = products.vend_id;

     

    在进行联结的过程中,就是将第一表中的每行数据与第二个表的每行元素进行配对,where语句只匹配符合条件的行

     笛卡尔积--就是将第一个表的行数将第二个表的行数相乘

    2. 内部联结(推荐使用)

    select vend_name,prod_name,prod_price from vendors INNER JOIN products on vendors.vend_id = products.vend_id;

    3. 联结多个表

    select prod_name,vend_name,prod_price,quantity from vendors,products,orderitems where vendors.vend_id = products.vend_id and products.prod_id = orderitems.prod_id and order_num = 20005;

    这个数据展示了订单号为20005中的产品,同时根据产品的生产商查询生厂商的信息

    SELECT cust_name, cust_contact
    FROM customers
    WHERE customers.cust_id = (
        SELECT cust_id
        FROM orders
        WHERE order_num = (
            SELECT order_num
            FROM orderitems
            WHERE prod_id = 'ANV01'
        )
    );
  • 相关阅读:
    给存储过程传递一个表
    Linker problems with Borland builder
    Python内置函数super的不便之处
    接口测试基础
    接口测试工具篇postman
    接口测试工具篇jmeter
    git的使用
    git与pycharm结合使用
    抓包工具fiddler
    sql 中 case when 语法
  • 原文地址:https://www.cnblogs.com/zhangchiblog/p/9163836.html
Copyright © 2011-2022 走看看