| 多表 SELECT 语句 / 创建连接 | |
多表连接在一个或多个相关联列上连接两个以上的表。它可以是等值连接或自然连接。
图: 查询
SELECT * FROM catalog, stock, manufact
WHERE catalog.stock_num = stock.stock_num
AND stock.manu_code = manufact.manu_code
AND catalog_num = 10025;
图: 查询结果
catalog_num 10025
stock_num 106
manu_code PRC
cat_descr
Hard anodized alloy with pearl finish; 6mm hex bolt hard ware.
Available in lengths of 90-140mm in 10mm increments.
cat_picture <BYTE value>
cat_advert ProCycle Stem with Pearl Finish
stock_num 106
manu_code PRC
description bicycle stem
unit_price $23.00
unit each
unit_descr each
manu_code PRC
manu_name ProCycle
lead_time 9
manu_code 重复三次,每个表一次,stock_num 重复两次。
图: 查询
SELECT catalog.*, description, unit_price, unit,
unit_descr, manu_name, lead_time
FROM catalog, stock, manufact
WHERE catalog.stock_num = stock.stock_num
AND stock.manu_code = manufact.manu_code
AND catalog_num = 10025;
图: 查询结果
catalog_num 10025
stock_num 106
manu_code PRC
cat_descr
Hard anodized alloy with pearl finish. 6mm hex bolt
hardware. Available in lengths of 90-140mm in 10mm increments.
cat_picture <BYTE value>
cat_advert ProCycle Stem with Pearl Finish
description bicycle stem
unit_price $23.00
unit each
unit_descr each
manu_name ProCycle
lead_time 9