Possible Duplicate:
Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?
I am working on a code base that often has
where 1=1
Often, these queries are complex and difficult to read. So it's not always feasible to break down the query semantics purely for a refactor. My gut instinct is that this is always unecessary. Maybe there exists a requirement for a where clause similar to the requirement for a Group By clause when performing a SELECT
with an aggregrate function alongside some column to group.
Is there ever a need for this?
It makes building dynamic WHERE clauses easier...
WHERE
1=1
AND condition1
AND condition2
This way you don't have to work out if you need the AND or not as you add conditions. You always need the AND.
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