Chapter XV: link

@author: Tobin
@date: 2019/10/31 19:06:27

Joining tables. This chapter is the equivalent link.
Understanding of relational databases. Each table contains one or more columns, uniquely identifies a row of data in another table, in another column, such a column is called the primary key.
In this table, called foreign keys.

SELECT vend_name, prod_name, prod_price
FROM vendors, products
WHERE vedors.vend_id == products.vend_id
ORDER BY vend_name, prod_name;
# 另外一种实现方法,也是推荐的方法,不容易忘记联结条件
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,quantity
FROM orderitems, products, vendors
WHERE products.vend_id = vendors.vend_id
AND orderitems.prod_id = products.prod_id
AND order_num = 20005;

Guess you like

Origin www.cnblogs.com/zuotongbin/p/11814161.html