所以我有一个名为users_chat_rooms的表:
mysql> describe users_chat_rooms;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| chat_id | int(11) unsigned | NO | MUL | NULL | |
+---------+------------------+------+-----+---------+----------------+
我有两个拥有唯一user_id的用户,我正在试图弄清楚如何找出他们共同的chat_id是什么。
谢谢!
答案 0 :(得分:2)
我这样加入:
print("\n".join(zip(*addresses)[0]))
#or maybe just
print(zip(*addresses)[0])
答案 1 :(得分:1)
这样的查询应该可以解决问题:
select chat_id
from users_chat_rooms
where user_id in (#USERID1#, #USERID2#)
group by chat_id
having count(distinct user_id) = 2