mysql if statement - is this possible? -


i sure mysql can dont have clue how write query.

if have following tables:

product id    name   product relationship parent_id    child_id    product category id    category_name   product categories product_id    category_id 

each product has list of categories allowed appear in , must visible in categories.

now difficult bit: if parent > child product relationship exists each child product id must considered part of rule , if child product not visible on category whole product must not visible.

visibility determined no result in result set returned query trying write here.

a typical input product id, parent , child ids if applicable , category id.

is possible single query , if how can write it?

i don't think case if in mysql (which can do), what's wrong subquery or more complex join e.g.

select   p.*   `product` p left join   `product_relationship` c   on p.id = c.parent_id or p.id = c.child_id   p.id in(     select product_id `product_categories`   )   , (     c.id null     or c.id in(       select product_id `product_categories`     ) 

disclaimer: haven't tested against schema


Comments