我想知道爲什麼聯合聲明非常流行,因爲許多字段可能在結果行中被複制。爲什麼使用連接語句?
Supplier(id, name, address)
Product(id, name, detail)
Product_Supplier(id, productId, supplierId, quantity)
SELECT Product.*,
Product_Supplier.supplierId,
Product_Supplier.quantity
FROM Product
INNER JOIN Product_Supplier ON Product.id = Product_Supplier.productId
結果可能是這樣的:
Product.id Product.name Product.detail Product_Supplier.supplierId Product_Supplier.quantity
1 'Product 1' 'bla bla' 100 20
1 'Product 1' 'bla bla' 101 30
1 'Product 1' 'bla bla' 102 20
1 'Product 2' 'bla bla' 100 120
所以,如果product.detail
大文本,然後性能會慢下來,對不對?如果這是真的,爲什麼加入聲明很受歡迎?
*我不知道爲什麼加入語句很受歡迎*?有沒有趨勢? – Raptor
[this]的可能重複(http://stackoverflow.com/questions/2241991/in-mysql-queries-why-use-join-instead-of-where) –
使用別名重命名輸出列名稱。 – Bohemian