basically i have a quest to do where i have to get all the details (product_purchase,price_history ,product colums that are name,type,id and price)from just searching for a product id.i basically did
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);
right now it just gives me the product id from product_purchase price_history and the id from product and i wanted it to show all the other colums from the 3 tables and want to have an option where i can do an input of the id something like
where product.id= %s
CodePudding user response:
Try this.
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%
But, as you will see, SELECT *
gives you some redundant columns. It's good practice to name the columns you want in your SELECT.... something like this, I guess.
SELECT price_history.product_id,
product.description,
product_purchase.vendor
...