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 negative consequences of this usage?
Here's a scrubbed example:
SELECT gpz.zname
,gpp.pname
FROM table1 gpp INNER JOIN table2 gpz ON gpz.p_id = gpp.p_id
WHERE 1=1
AND gpp.active = 1
AND gpz.active = 1
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With