为什么 sql 查询会有“where 1 = 1"? [英] Why would a sql query have "where 1 = 1"

查看:22
本文介绍了为什么 sql 查询会有“where 1 = 1"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些我正在维护的查询,一位程序员向我输入了where 1=1"的查询,这些查询似乎总是评估为真.

I was going through a few queries I am maintaining, and a programmer had put in the queries "where 1=1" to me that always seems to evaluate to true.

这样做有好处吗?

重复: 为什么有人会在 SQL 子句中使用 WHERE 1=1 AND ?

那个问题不是这个问题的答案.

That question isn't an answer to this question.

Where-子句:

select * from table where 1=1 and sStatus not in ('status1','status2','status3')

无需编程或 if 语句将 and 推入其中.直接查询.

No programming or if statements to push an and in there. A straight query.

如果你可以取消关闭这个,我想知道是否有一个目的,以便我可以在不需要时重写并删除1 = 1.

If you could un-close this, I would like to know whether there is a purpose so that I may rewrite and remove the 1=1 if it is unnecessary.

推荐答案

是动态查询吗?有时这在基于可选参数构建动态查询时很有帮助.

Was it dynamic queries? Sometimes that's helpful when building dynamic queries based on parameters that are optional.

这篇关于为什么 sql 查询会有“where 1 = 1"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆