[英]MySQL select rows with two where conditions and count greater than 1 with same column ID
In this example the result should be conversation_id 165337: 在此示例中,结果应为session_id 165337:
Here is the MySQL I have so far which does not work: 这是到目前为止我无法使用的MySQL:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id
FROM xf_conversation_recipient
WHERE user_id = '4465'
AND user_id = '1'
HAVING COUNT(DISTINCT conversation_id) > 1
");
Here is the answer and code which works: 这是有效的答案和代码:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
WHERE user_id IN ('4465','1')
GROUP BY conversation_id HAVING c > 1
");
Try this then: 然后尝试以下方法:
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
GROUP BY conversation_id HAVING c > 1;
and in your case: 和你的情况:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
WHERE user_id IN ('4465','1')
GROUP BY conversation_id HAVING c > 1
");
WHERE user_id = '4465' AND user_id = '1'
正确
WHERE user_id = '4465' OR user_id = '1'
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id FROM xf_conversation_recipient WHERE user_id IN ('4465','1') HAVING COUNT(*) > 1
");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.