SQL query: Simulating an “AND” over several rows instead of sub-querying

后端 未结 5 1149
轮回少年
轮回少年 2020-11-29 08:07

Suppose I have a \"tags\" table with two columns: tagid and contentid. Each row represents a tag assigned to a piece of content. I want a

5条回答
  •  攒了一身酷
    2020-11-29 08:29

    The only alternative way i can think of is:

    select a.contentid from tags a
    inner join tags b on a.contentid = b.contentid and b.tagid=334
    inner join tags c on a.contentid = c.contentid and c.tagid=342
    where a.tagid=338
    

提交回复
热议问题