MySQL table 加入数据库?
MySQL table join in database?
我想知道mysql我怎样才能形成一个新的table来显示我想要的数据?
Current having Purchase table and Product table
我的产品table:
=====Product=====
field productID
field category
field brand
field name
field createtime
我的购买 table:
=====Purchase=====
field UID
field productID
field username
field email
field purchaseDate
结果table我希望得到:
=====OrderList=====
field UID
field productID
field category
field brand
field name
field username
field email
field purchaseDate
我的疑问,一旦在 Purchase table 中插入新记录,mysql OrderList table 会在数据库中自动更新吗?
below is the example method do this solve my problem?
SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand,
Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate
FROM Product
LEFT JOIN Purchase
ON Product.productID=Purchase.productID
如果您想要自动更新您的 OrderList table,那么您将需要创建一个视图,而不是静态的 table:
create or replace view OrderList as
SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand,
Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate
FROM Product
LEFT JOIN Purchase
ON Product.productID=Purchase.productID
ORDER BY Customers.CustomerName;
使用"VIEW",例如:
CREATE VIEW OrderList
AS
SELECT Purchase.UID,
Purchase.productID,
Product.category,
Product.brand,
Product.name,
Purchase.username,
Purchase.email,
Purchase.purchaseDate
FROM Product, Purchase
WHERE Product.productID = Purchase.productID
ORDER BY Customers.CustomerName
我想知道mysql我怎样才能形成一个新的table来显示我想要的数据?
Current having Purchase table and Product table
我的产品table:
=====Product=====
field productID
field category
field brand
field name
field createtime
我的购买 table:
=====Purchase=====
field UID
field productID
field username
field email
field purchaseDate
结果table我希望得到:
=====OrderList=====
field UID
field productID
field category
field brand
field name
field username
field email
field purchaseDate
我的疑问,一旦在 Purchase table 中插入新记录,mysql OrderList table 会在数据库中自动更新吗?
below is the example method do this solve my problem?
SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand,
Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate
FROM Product
LEFT JOIN Purchase
ON Product.productID=Purchase.productID
如果您想要自动更新您的 OrderList table,那么您将需要创建一个视图,而不是静态的 table:
create or replace view OrderList as
SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand,
Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate
FROM Product
LEFT JOIN Purchase
ON Product.productID=Purchase.productID
ORDER BY Customers.CustomerName;
使用"VIEW",例如:
CREATE VIEW OrderList AS SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand, Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate FROM Product, Purchase WHERE Product.productID = Purchase.productID ORDER BY Customers.CustomerName