西安做网站_西安网站建设公司_西安网页制作_西安网页设计_西安网站制作设计公司

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8852|回复: 0

mysql 语句中的in、find_in_set、like的区别

[复制链接]
发表于 2017-5-16 11:39:42 | 显示全部楼层 |阅读模式

1.in查询相当于多个or条件的叠加,例如:

select * from user where user_id in (1,2,3);
等效于
select * from user where user_id = 1 or user_id = 2 or user_id = 3;
not in与in相反,如下
select * from user where user_id not in (1,2,3);
等效于
select * from user where user_id != 1 and user_id != 2 and user_id != 3;

1.find_in_set基本语法

FIND_IN_SET(str,strlist)

str 要查询的字符串,strlist 字段名 参数以”,”分隔 如 (1,2,6,8)
如果str不在strlist 或strlist 为空字符串,则返回值为 0 。如任意一个参数为NULL,则返回值为 NULL。这个函数在第一个参数包含一个逗号(‘,’)时将无法正常运行。

+----+---------+-----------+-------------+
| id | user_id | follow_id | follow_time |
+----+---------+-----------+-------------+
| 13 | 15      | 16,15     |  1478096138 |
| 14 | 15      | 17        |  1478177725 |
| 15 | 15      | 19        |  1478181035 |
+----+---------+-----------+-------------+

比如这张表,SELECT * from test where FIND_IN_SET('5',follow_id);这样是查不到的,返回值为null,因为follow_id中没有”5”这个值,它不同于 like 模糊查询,它是以“,”来分隔值

like是广泛的模糊匹配,字符串中没有分隔符,Find_IN_SET 是精确匹配,字段值以英文”,
”分


西安网站建设 | 西安做网站 —— 剑锋所指 所向披靡!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西安网站建设

GMT+8, 2024-4-20 09:27 , Processed in 0.043492 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表