Pregunta

In this example the result should be conversation_id 165337:

enter image description here

Here is the MySQL I have so far which does not work:

$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
");
¿Fue útil?

Solución

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
");

Otros consejos

WHERE user_id = '4465' AND user_id = '1' 

correct

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
");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top