I\'m working with a client that starts almost all of their WHERE clauses in Oracle with 1=1
. Forgive my ignorance, but isn\'t this a no-op? Are there any negati
They may have built the query from substrings.
It may be a way to build it with just AND
s, depending on the business rule match, so you don't really have to care which is your first condition.
Wouldn't do it that way myself.
If they are building the query dynamically, you should check whether they're using bind variables. Building the query from literals requires extra parsing, potentially limiting scalability, and also can greatly increase the risk of SQL Injection attacks.
where 1 = 1 and my_id = :b1;
(and then defining the value of the bind variable)
is generally much better than:
where 1 = 1 and my_id = 123456;
It's done to simplify dynamic SQL generation. Basically each condition can be added as AND <condition>
without treating the first condition as special (it's preceded by WHERE
not AND
) or even worrying if there should be a WHERE
clause at all.
So just write it off as easy of use or, arguably, laziness.