php - select query records if multiple type is matched -


i have mysql tables below,

1)videos

id      name 1       test1 2       test2 

2)tags

id      name 1       theme1=test1 2       theme1=test2 3       theme2=test1 4       theme2=test2 5       age=senior 6       age=children 

3)tags_to_items

vid    tagid 1      1 1      5 

here in table tags_to_item see videos.id=1 has 2 tags 1)theme1=test1 , 2)age=senior. means video.id=1 has 2 tags. here 1 conflict, doing is, searching theme's only. means if search theme1=theme1 need search theme1 in theme2 , vice versa. this

where tagid=1 or tagid=2 

this functioning proper, want search if video have multiple tag , condition this

where tagid=5 , tagid in (1,2) 

it should return video.id=1

so, need search video 1 contains tag tag age=senior , theme1=theme1 or theme2=theme1. not working, have idea how can this?

i think got answer. need join this,

inner join tags_to_items t2      on (v.id = t2.tagid , t2.tagid = 5)   inner join tags_to_items t3      on (v.id = t3.tagid , t3.tagid in ('27' ,'69','84' ,'99' ))  

Comments