I came across a view in our database today where the first statement in the where clause was where 1 = 1. Shouldn't this return true for every record? Why would someone write this if it isn't filtering any records?
Tell me more
×
Database Administrators Stack Exchange is a question and answer site for
database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
|
|
|||||||
|
|
Some dynamic query builders include this condition so that any "real" conditions can be added with an |
|||||||||||
|
|
It provides a situation that is always true, so it doesn't affect the results, but you know there is one item in the WHERE clause already. |
|||
|
|
|
If you have many SQL statement building points in your program which generate similar queries, you can mark the examined one by this trick. If the sentence is about counting, you may use select count(42) from table, so you can grep out "42" from a SQL log. |
|||
|
|