0

In several codes on the web I have found the following sentence

SELECT *
  FROM <TABLE>
 WHERE 1=1  
   AND ....

I can't understand what purpose this comparison has to do.

Gdaimon
  • 269
  • 1
  • 3
  • 16
  • That is usually inserted by automatically generated code. It makes is slightly easier to add conditions just using `AND `. – Gordon Linoff Jul 24 '19 at 17:54
  • https://stackoverflow.com/questions/242822/why-would-someone-use-where-1-1-and-conditions-in-a-sql-clause – kfinity Jul 24 '19 at 17:54
  • When you start with a WHERE 1=1, you can dynamically add new filters with just AND... – Hans Kesting Jul 24 '19 at 17:55
  • This is because it's useful for adding and removing conditions in code. It's really helped. – Hasan Mahmood Jul 24 '19 at 17:55
  • It's used by lazy programmers that generate SQL statements dynamically and don't want to keep track if they already added a condition or not –  Jul 24 '19 at 18:18

0 Answers0