我試圖列出所有銷售包含吉他裝備的特定吉他部件的產品的商店。MySQL:通過多個表引用時返回多於一行
我有一個guitarRig
數據庫。吉他鑽機具有parts
(即amplifier
,cabinet
,microphone
,guitarType
,guitarStringType
,patchCord
,effectsPedal
),它來自於產品,這是從商店購買。 產品的購買價格由我的PurchaseInformation
表格決定。
這裏是我的表:
Table Part:
name
guitarRig references GuitarRig(name)
product references Product(name)
Table Product:
name
part references Part(name)
barcodeNumber
Table PurchaseInformation:
price
product references Product(name)
purchasedFrom references Store(name)
Table Store:
name
storeLocation
到目前爲止,我已經是這樣的:
SELECT p.name AS Part, prod.name AS Product, sto.name AS Store
FROM Part p, ProductInformation prod, Store sto, PurchaseInfo purch
WHERE sto.storeNumber = purch.storeNumber
AND purch.product = prod.name
AND prod.Part = p.name
AND p.name =
(
SELECT name
FROM Part
WHERE name LIKE '%shielded%'
)
GROUP BY p.name;
我得到的錯誤然而,它返回超過1行,這是我想要的!我想列出銷售包含我正在搜索的零件的產品的商店。