MySQL in-operator必须匹配所有值吗? [英] MySQL in-operator must match all values?
本文介绍了MySQL in-operator必须匹配所有值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经建立了自己的论坛.搜索时,我想找到两个(或更多)特定用户参与的线程.我想到了这个:
I've made my own forum. When doing a search I want to find any threads where two (or more) specific users have participated. I came up with this:
SELECT * FROM table1 INNER JOIN table2
ON table1.threadid=table2.threadid
WHERE table2.threadcontributor IN ('1','52512')
在意识到它实际上意味着'1' OR '52512'
之前.
Before realizing that it actually means '1' OR '52512'
.
有什么办法可以使所有id都匹配吗?
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
这篇关于MySQL in-operator必须匹配所有值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文