Multiple tags search query

后端 未结 4 789
深忆病人
深忆病人 2021-01-02 12:24

I working on a tag based search. I have three tables tag(id,name), tagXmedia(id,tag_id,media_id), and media(id,...). tagXmedia is the mapping table between the tag and media

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 12:50

    Try this query:

    SELECT
        T1.media_id
    FROM
        tagXmedia as T1
    INNER JOIN media as T2 
    ON T1.media_id =T2.id
    INNER JOIN tag as T3 
    ON T1.id = T3.tag_id AND T3.name IN ('home','hawaii')
    GROUP BY T1.media_id
    

提交回复
热议问题