SQL for applying conditions to multiple rows in a join

前端 未结 11 2055
一个人的身影
一个人的身影 2020-11-29 22:55

I think I found the answer to my question, I\'m just unsure of the syntax, I keep getting SQL errors.

Basically, I want to do the opposite of IN. Take this example:<

11条回答
  •  感动是毒
    2020-11-29 23:17

    select * from users u
    where 2 = (select count(*) from tags t where t.user_id = u.id and name in ('tag1','tag2'))
    

    Assuming that any given tag can only be present once per user.

提交回复
热议问题