Search code examples
sqlmany-to-many

SQL ManyToMany. How select product from category '1'


Hello i'm beginner in SQL and i do not understand how to:

select product from category where id='1'. 

I have 3 tables:

product: id | name
category: id | name
category_product: product_id | category_id

Solution

  • Is this you want? Make use of join

    select 
       name 
    from product pr 
    join category_product cp on (cp.product_id = pr.id) 
    where cp.catagory_id = '1'