0

Why would someone use WHERE 1=1 AND <conditions> in a SQL claus. I don't understand why would someone use this construction for defining a view, or use it inside a stored procedure.

for example:

select * from user where 1=1
sia
  • 513
  • 4
  • 14
  • That seems totally not useful, since `select * from user` would return the same results. – rory.ap Dec 23 '14 at 14:43
  • I've not seen it - I would look forward to anyone who can explain. – PhillipH Dec 23 '14 at 14:44
  • 1
    I've used it when I'm doing some data analysis and I want to quickly add and comment out other filter conditions that follow in subsequent lines. – sam yi Dec 23 '14 at 15:09
  • 1
    I've also used it - if you don't know whether there will be any conditions or their order until runtime it can simplify the generating code. It always feels a bit "hacky" though. – Sonic Dec 23 '14 at 15:18

0 Answers0