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

后端 未结 5 1164
轮回少年
轮回少年 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:12

    I don't know if this is better but it might be more maintainable

    select contentid from tags where tagid = 334
    intersect
    select contentid from tags where tagid = 338
    intersect
    select contentid from tags where tagid = 342
    

    You'd have to build it dynamically which wouldn't be as bad as your original solution.

提交回复
热议问题