mysql in list only validates first id in list. maybe a blob issue(列表中的 mysql 仅验证列表中的第一个 id.也许是斑点问题)
问题描述
我使用的系统使用逗号分隔值作为一对二的关系.它以 blob 形式存储.
I work with a system that used comma separated values as a one-2-many relation. It is stored in as a blob.
我尝试使用 MySQL IN (LIST),但最终只得到 uid 在列表中第一个或只有一个在列表中的行.
I try to use the MySQL IN (LIST), but only ends up with the rows where the uid is first in the list or only one in the list.
mytable
uid categories
1 24,25,26
2 25
3 22,23,25
4 25,27
run sql:
SELECT * FROM mytable WHERE 25 IN (categories)
Result:
uid categories
2 25
4 25,27
Missing (should have been selected but are not)
uid categories
1 24,25,26
3 22,23,25
知道为什么字符串必须以 25 开头而不是只包含 25 吗?我想这是一个字符串问题而不是 IN (LIST) 问题
Any idea why a string has to start with 25 and not just contain 25? I guess it is a string issue rather than an IN (LIST) issue
更新 - 基于以下答案:
在 blob 上使用 th IN (LIST) 时,blob 将转换为 int 并且逗号和数字"丢失.
When using th IN (LIST) on a blob, the blob is converted to an int and commas and "digits" are lost.
改为使用 FIND_IN_SET(needle, haystack),它也适用于包含逗号分隔值的 blob.
In stead use FIND_IN_SET(needle, haystack) that will work also on a blob containing comma separated values.
推荐答案
我认为您正在寻找 FIND_IN_SET
SELECT * FROM mytable WHERE FIND_IN_SET(25,category)
这篇关于列表中的 mysql 仅验证列表中的第一个 id.也许是斑点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:列表中的 mysql 仅验证列表中的第一个 id.也许是斑点问题


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01