mysql 中 is true 和 =true 结果不一致的原因
在 mysql 中查询数据时,使用 is true 和 =true 作为条件会导致不同的结果。这是因为这两个操作具有不同的语义:
示例
已知表结构如下:
create table user ( id int not null auto_increment, is_deleted tinyint(1) not null default 0, primary key (id) );
插入的示例数据:
insert into user (is_deleted) values (127); insert into user (is_deleted) values (0);
查询结果
执行以下查询语句:
select * from `user` where is_deleted is true;
结果:
+----+------------+ | id | is_deleted | +----+------------+ | 1 | 127 | +----+------------+
执行以下查询语句:
select * from `user` where is_deleted = true;
结果:
空集
可见,使用 is true 查询到了 is_deleted 为 127(非 0)的记录,而使用 =true 未查询到任何记录。
以上就是MySQL 中 IS TRUE 和 =True 查询结果不一致的原因是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号