why would you use WHERE 1=0 statement in SQL?

后端 未结 12 2218
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 00:48

I saw a query run in a log file on an application. and it contained a query like:

SELECT ID FROM CUST_ATTR49 WHERE 1=0

what is the use of s

12条回答
  •  忘掉有多难
    2020-12-08 01:19

    quoted from Greg

    If the list of conditions is not known at compile time and is instead built at run time, you don't have to worry about whether you have one or more than one condition. You can generate them all like:

    and

    and concatenate them all together. With the 1=1 at the start, the initial and has something to associate with.

    I've never seen this used for any kind of injection protection, as you say it doesn't seem like it would help much. I have seen it used as an implementation convenience. The SQL query engine will end up ignoring the 1=1 so it should have no performance impact.

    Why would someone use WHERE 1=1 AND in a SQL clause?

提交回复
热议问题