mysql join with a "bounce" off a third table
Posted
by Enkay
on Stack Overflow
See other posts from Stack Overflow
or by Enkay
Published on 2010-04-25T20:44:54Z
Indexed on
2010/04/25
20:53 UTC
Read the original article
Hit count: 227
I have 3 mysql tables.
companies with company_id and company_name
products with product_id and company_id
names with product_id, product_name and other info about the product
I'm trying to output the product_name and the company_name in one query for a given product_id.
Basically I need information from the names and companies tables and the link between them is the products table.
How do I do a join that needs to "bounce" off a third table?
Something like this but this obviously doesn't work :
SELECT product_name, company_name
FROM names
LEFT OUTER JOIN companies ON
(names.product_id = products.product_id and products.company_id = companies.company_id)
WHERE product_id = '12345'
Thanks!
© Stack Overflow or respective owner