Filtering from join-table

后端 未结 2 1768
鱼传尺愫
鱼传尺愫 2021-01-21 10:46

I\'m having some trouble with a tricky SQL-query.

In my MySQL database there is the tables topics, tags and tags_topics to join them. I want to fetch topics that share

2条回答
  •  [愿得一人]
    2021-01-21 11:15

    SELECT 
        topic_id
    FROM
        tags_topics
    WHERE
        tag_id IN (1,2,3)
    GROUP BY
        topic_id
    HAVING
        COUNT(*) > 2  /* or use COUNT(*) = 3 if you know that there cannot be duplicates in the junction table */
    

提交回复
热议问题