mySql IN条件的一点注意项

来源:互联网 发布:知乎咖啡的好处与坏处 编辑:程序博客网 时间:2024/05/20 09:24

大家先看看下面的 4条 sql 语句 的执行结果有什么异同?

首先,说一下前提条件:在数据库中,表 test 的 id 字段 是bigint类型。


1、select t.user_name from test t where t.id = ('7385,8441,9795,8524,7796,8393,8894');

2、select t.user_name from test t where t.id in ('7385,8441,9795,8524,7796,8393,8894');

3、select t.user_name from test t where t.id in ('7385','8441','9795','8524','7796','8393','8894');

4、select t.user_name from test t where t.id in (7385,8441,9795,8524,7796,8393,8894);


第一条 和 第二条 sql 语句执行后的结果等同于:

select t.user_name from test t where t.id=7385;

也就是只查询出了第一个的用户名。


第三条 和 第四条 sql 语句查询出了所有 in 条件里的用户名。

0 0
原创粉丝点击