开发者

MySQL in-operator must match all values?

开发者 https://www.devze.com 2023-04-06 07:22 出处:网络
I\'ve made my own forum. When doing a search I want to find any threads where two (or more) specific users开发者_如何学Go have participated. I came up with this:

I've made my own forum. When doing a search I want to find any threads where two (or more) specific users开发者_如何学Go have participated. I came up with this:

SELECT * FROM table1 INNER JOIN table2 
ON table1.threadid=table2.threadid 
WHERE table2.threadcontributor IN ('1','52512')

Before realizing that it actually means '1' OR '52512'.

Is there any way to make it work so that all id's has to match?


SELECT * 
    FROM table1 
        INNER JOIN table2 
            ON table1.threadid=table2.threadid 
    WHERE table2.threadcontributor IN ('1','52512')
    GROUP BY table1.PrimaryKey
    HAVING COUNT(DISTINCT table2.threadcontributor) = 2
0

精彩评论

暂无评论...
验证码 换一张
取 消