【发布时间】:2017-04-18 13:17:47
【问题描述】:
我想知道如何在 SQL 中执行以下操作:
SELECT *
FROM table_A
WHERE id IN(:myValues)
AND other_colum has the same value
例如,如果我有一个会话表 (iduser,idconversation),我希望 SQL 查询返回一些具有相同会话 ID 的 Id。它应该返回
35;105
37;105
35;106
37;106
他们有 35,37 个 idUser 和 105,106 个对话。
为了更进一步,我使用 Doctrine 和 PostegreSQL,生成了我要查询的表 (多对多关系),但我很难集成子查询。
**public function getAllCommonConversationByUserId($ids)
{
return $this->createQueryBuilder('c')
->select('c.id')
->innerJoin('c.idUser', 'recievedConversation')
->where('recievedConversation IN (:ids)')
->andWhere('$qb->expr()->eq("SELECT id FROM table GROUP BY(id) HAVING COUNT(*) >1")')
->setParameter(':ids', $ids)
->getQuery()
->getResult();
}**
【问题讨论】:
-
您使用的是哪个 DBMS?后格雷斯?甲骨文?
-
我使用 PostgreSQL 和学说
标签: sql postgresql doctrine