mysql in和find_in_set
2024-10-21 04:59:11
一、查询包含“,”的列
1.如果查询条件包含单引号
用in
如:select * from t_test where names in ('李红');
只能查询出names列中值为‘李红’的数据
select * from t_test where names in ('李红,李华');
只能查询出names列中值为‘李红,李华’的数据
用find_in_set
如:select * from t_test where FIND_IN_SET('李红',names );
能查出names列中包含‘李红’的列 如:李红,李华;李丽,李红;小明,李红
select * from t_test where FIND_IN_SET('李红,李华',names );
不能查询任何数据
2.如果查询条件不包含单引号
用in
如:select * from t_test where names in (李红);
只能查询出names列中第一个值为‘李红’的数据。 如:李红,李华;李红,小明;不能查出:小明,李红。
select * from t_test where names in (李红,李华);
只能查询出names列中第一个值为‘李红‘的数据。
用find_in_set
如:select * from t_test where FIND_IN_SET(李红,names );
能查出names列中包含‘李红’的列 如:李红,李华;李丽,李红;小明,李红
最新文章
- 在Ubuntu 16.10 安装 git 并上传代码至 git.oschina.net
- C#_技巧:真伪随机数
- JBoss AS
- Thinkphp源码分析系列(九)–视图view类
- asp.net“服务器应用程序不可用” 解决方法
- LICEcap
- svn配置
- Android环境rm命令
- UVA 657 The die is cast
- 通过MYSQL命令行直接建数据库
- centos 7 epel地址
- ecshop开发日志之支付插件开发
- aspx向silverlight传值
- eclipse环境下如何配置tomcat
- SQL之Left Join 关联条件的探讨
- 『计算机视觉』物体检测之RefineDet系列
- EFCore Lazy Loading + Inheritance = 干净的数据表 (一) 【献给处女座的DB First程序猿】
- WebSocket简单尝试
- C#语言————第四章 常用Convert类的类型转换方法
- StackExchange.Redis 管道 批量 高性能插入数据