Reputation: 21895
I have two tables :
Products table :
Family table :
I want to get all the family_name
records of the products that have the same family_code
as in the family
table :
SELECT family_name
FROM family
LEFT JOIN products
ON products.family_code=family.family_code;
But this code return all the family_name
records .
Any idea where did I go wrong ?
Much appreciated
Upvotes: 1
Views: 31
Reputation: 4583
If you do an INNER JOIN, it will only show you records which are in both tables. A LEFT JOIN will show all records from family regardless of whether they have a matching products table entry.
SELECT f.family_name
FROM family f
INNER JOIN products p
ON f.family_code=p.family_code;
Upvotes: 2