Reputation: 4878
I know how to get a single record from multiple tables using Join. How do you get multiple records?
E.G
Table: categories
id
name
description
Table: some_table
id
name
content
category_id
How would I extend the basic query below to pull all records from within all categories?
SELECT c.id, c.name as category_name FROM categories AS c
Upvotes: 0
Views: 54
Reputation: 14946
The exact join depends on your needs, but the following will show all data from category and some_table where there is at least one row in some_table that matches the value in category. Empty categories will not be shown; you can use a LEFT JOIN instead if you want to show empty category records with NULL values for the records that would otherwise come from the some_table table.
SELECT *
FROM categories c
INNER JOIN some_table st ON (c.id = st.category_id);
Upvotes: 2