mysql - How to query 2 tables relation of which is described by another pk to pk table? -
i have db of 3 tables: categories
, items
, relation
. categories
contain categories. goods stored in items
, relation
binding table, stores product id , category id or categories.
how can given list of items, names of categories?
you can try left join
this.
select * items left join relation r on i.id = r.id_items left join categories c on r.id_cat = c.id
hope helps.
above query give items note mapped in relation table while below query give items has defined relation in table relation
select * items right join relation r on i.id = r.id_items left join categories c on r.id_cat = c.id
let me know if error.
Comments
Post a Comment