patternCritical
Why use WHERE 1 or WHERE 1=1?
Viewed 0 times
whywhereuse
Problem
Usually, if conditions are not required in our query statements, we don't use a
WHERE clause. But I've seen a WHERE 1 clause being used in many places, even where other conditions are not present.- Why is this done?
- Are there specific benefits to the execution time?
- Does it enable other functionalities?
- Is using
WHERE 1=1similar to this?
Solution
Basically it is just for programmer convenience since you can just add additional conditions with
Check out these links to Stackoverflow:
clause?
statement
Note that
AND... after that and it has no impact on execution time.Check out these links to Stackoverflow:
- Why would someone use WHERE 1=1 AND in a SQL
clause?
- “where 1=1”
statement
Note that
WHERE 1 is identical to WHERE 1=1; both mean WHERE TRUE but the former is rejected by many database management systems as not really being boolean.Context
StackExchange Database Administrators Q#54954, answer score: 61
Revisions (0)
No revisions yet.