基本上我有一個任務,我必須從搜索產品 id 中獲取所有詳細資訊(product_purchase、price_history、名稱、型別、id 和價格的產品列)。我基本上做到了
select price_history.product_id, product.id, product_purchase.product_id from ((price_history
inner join product on price_history.product_id = product.id)
inner join product_purchase on price_history.product_id = product_purchase.product_id);
現在它只給了我來自 product_purchase price_history 的產品 ID 和來自 product 的 id,我希望它顯示 3 個表中的所有其他列,并希望有一個選項,我可以輸入 id 之類的東西
where product.id= %s
uj5u.com熱心網友回復:
試試這個。
SELECT *
FROM price_history
INNER JOIN product
ON price_history.product_id = product.id
INNER JOIN product_purchase
ON price_history.product_id = product_purchase.product_id
WHERE product_id = %substitutedParameter%
但是,正如您將看到的,SELECT *會為您提供一些多余的列。在你的 SELECT 中命名你想要的列是一個很好的做法......像這樣,我猜。
SELECT price_history.product_id,
product.description,
product_purchase.vendor
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/381371.html
標籤:sql
