mysql - MySQL:选择具有特定字段值的多行
问题描述
我有一个 users_conversations 表,其中包含一个 conversation_id 和一个 user_id 来告诉哪些用户在同一个对话中。我想找到具有 user_id 76 和 user_id 146 的任何 conversation_id(它们是 ids 28、31 和 32。这些 id 对我来说并不陌生。我只有两个用户 id)我试过
select * from users_conversations where user_id = 146 or user_id = 76 GROUP BY conversation_id
但我明白了
#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
'forums.users_conversations.user_id' which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
我怎样才能做到这一点?
解决方案
select * from users_conversations
where conversations_id in (select conversations_id from user_conversations where user_id=76)
AND conversations_id in (select conversations_id from user_conversations where user_id=146)
推荐阅读
- javascript - TypeScript 和 Axios 响应类型
- git - 致命的:太多的论点。PowerPoint 改变了我的 git 命令
- java - Unicode 代码点数组转换为字符串并返回更改
- xquery - 如何在 Marklogic 中使用 Xquery 从数百万条记录中获取 CustomerId
- java - Spring将评论实体添加到显示页面上的发布实体
- html - HTML 中的多个页面
- ssl - 如何避免 ESP32 的 mosquitto pub 和 sub 中的 ca 证书
- jquery - 结合 Json api 响应和我自己的 Json 数据时出错
- python - Python:如何生成一个序列,每个 m 个数字跳过 n 个数字
- java - 如何添加和删除