Why do we write WHERE 1=0 or 1=1 in SQL query under WHERE clause?
1 Answer
It's just used to make it easier to concatenate extra conditions to the WHERE clause. For example:
var sql = "SELECT * FROM Person WHERE 1=1 "; if(something) sql += " AND Something = 1"; if(somethingElse) sql += " AND SomethingElse = 1"; This way you don't need to check if it is the first condition or not, you can always append AND at the start.
1=1reference, to the correct1=0duplicate as in the previous comment. I would suggest to reopen, and then again marking it as duplicate using the correct reference. Even though the body of the question rephrases the question to both 1=0 and 1=1, the 1=0 question has better quality answers that reflect those both scenarios as well.