Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to do inner join of some colums but still show the other colums if thats possible

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading