Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create INNER JOIN multiple tables in sql

I have 3 tables: Products, Vendors and Prices. Prices has product_id and vendor_id as foreign keys. Now i want to show Prices as:

price_id:product_name:vendor_name:price

Something like:

SELECT p.product, v.vendor, pc.price
FROM Products AS p,
Vendors AS v
INNER JOIN Prices AS pc
ON p.product_id = pc.product_id
INNER JOIN Prices AS pc
ON v.vendor = pc.vendor_id

but I didnt get it work.

like image 284
user_unknown Avatar asked May 20 '26 01:05

user_unknown


1 Answers

Try this:

SELECT pr.price_id, p.product_name v.vendor_name, pr.price
FROM Prices AS pr
LEFT JOIN Products AS p ON p.product_id = pr.product_id
LEFT JOIN Vendors AS v ON v.vendor = pr.vendor_id
like image 162
Marek Kwiendacz Avatar answered May 21 '26 14:05

Marek Kwiendacz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!