mysql - Mysql 通过乘以 id 过滤
问题描述
我无法完成编写查询以通过乘以 id 过滤行。这是查询:
select distinct `storage_file`.*, `storage_tag`.`id` as `tid` from `storage_file`
inner join `storage_file_tag` on `storage_file`.`id` = `storage_file_tag`.`storage_file_id`
inner join `storage_tag` on `storage_tag`.`id` = `storage_file_tag`.`storage_tag_id`
where `storage_file`.`user_id` = 17 and `storage_file`.`deleted_at` is null and
`storage_tag`.`id` IN(13,17);
所以结果是没有 group by 语句是:
所以.. 我只需要包含 tid 13 和 17 的两条记录的结果,当我将“IN(13,17)”替换为storage_tag
. id
= 13 和storage_tag
。id
= 17 - 我没有得到任何记录
我怎样才能编写像a
+b
但不是a
OR的子查询b
?
解决方案
你可以更换
... AND id IN (11,22)
和
... AND ( id = 11 OR id = 12)
您需要括号,因为 WHERE 运算符优先级规则非常简单。
当然,
... AND id = 11 AND id = 12
从不返回任何内容,因为 id 不能同时具有两个不同的值。
推荐阅读
- html - 我怎样才能移动整个包含使用绝对定位定位的图像?
- c# - 在 C# 中检查网络连接?
- react-native - 在 react-native 中确定触摸侧
- oracle - 如何查找在 SELECT (Oracle) 中引发错误的记录
- python - 具有回答条件的最大值的 DataFrame 行
- python - Python 合并相似的列表值,从定义的字符数到新的列表值
- android - 片段恢复时 LiveData 不会重新发送
- java - 从 Java 8 中的地图列表中获取字符串
- ansible - 如何从 Ansible 中的所有主机获取变量?
- python-3.x - 为什么我的 GAN 在某个点之后没有产生更多好的图像?