Why would someone use WHERE 1=1 in a SQL clause?

If the list of conditions is not known at compile time and is instead built at run time, you don't have to worry about whether you have one or more than one condition. You can generate them all like: and <condition>  and concatenate them all together.

it used as an implementation convenience. 

The SQL query engine will end up ignoring the "1=1" so it should have no performance impact.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,131评论 0 23
  • 调用insert(_:atIndex:)方法在某个具体的索引值之前添加数据项: 在索引是0得位置插上了“maple...
    SheBang_阅读 275评论 0 0
  • 我是一只魅,行走于三界之中,忘却于六道之外。 我姓苏,名唤益清,这是我师父余初所赐。
    平生尽阅读 100评论 0 0
  • Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件。本文简单介绍了在项目中集成swagg...
    GhostStories阅读 2,671评论 2 13