Lots of same answers here. For some reason, though, all of them are joining the Section
table which is (likely) not necessary.
select
p.*
from
Product p,
Category c
where
p.category_id = c.id and
c.section_id = 123
;
Explicit ANSI JOIN
syntax per @nemiss's request:
select
p.*
from Product p
join Category c
on c.id = p.category_id
and c.section_id = 123
;
Possible reason to include Section
table: Selecting products based on Section name (instead of ID).
select
p.*
from Product p
join Category c
on c.id = p.category_id
join Section s
on s.id = c.section_id
and s.name = 'Books'
;
If doing this, you'll want to make sure Section.name
is indexed
alter table Product add index name;