从两个ID中查找具有相同值的行

时间:2015-04-05 16:41:02

标签: mysql

我正在寻找一个查询来从我的函数的两个participant_id参数中获取会话ID:

获取conversation_id的Php函数

public function findByUsers($user1,$user2)

Mysql表participant_conversation

+--------------+-------------------------+
|participant_id| participant_conversation|
+--------------+-------------------------+
|42360         |1                        |
+--------------+-------------------------+
|42362         |5                        |
+--------------+-------------------------+
|42363         |1                        |
+--------------+-------------------------+

感谢您的帮助

编辑:我找到了解决方案

SELECT DISTINCT ( participant_conversation ) 
FROM users_conversations_participants 
WHERE participant_id IN ( 42360, 42361 ) 
GROUP BY participant_id 
LIMIT 0 , 30

1 个答案:

答案 0 :(得分:0)

以下问题:

$sql = "SELECT participant_id, participant_conversation FROM participant_conversation WHERE participant_id IN ($user1, $user2)";

然后可以简单地使用while循环来获取各自的participant_converation。