{"id":624,"date":"2015-03-22T08:30:55","date_gmt":"2015-03-22T07:30:55","guid":{"rendered":"http:\/\/bar-solutions.com\/weblog\/?p=624"},"modified":"2015-03-22T08:30:55","modified_gmt":"2015-03-22T07:30:55","slug":"whats-this-where-11","status":"publish","type":"post","link":"https:\/\/blog.bar-solutions.com\/?p=624","title":{"rendered":"What&#8217;s this &#8216;WHERE 1=1&#8217;?"},"content":{"rendered":"<p>Since some time I have been adding <code>WHERE 1=1<\/code> to all my queries.     <br \/>I get queries like this:<\/p>\n<pre>SELECT *\r\n  FROM emp e\r\n WHERE 1=1\r\n   AND e.ename LIKE 'A%'\r\n   AND e.deptno = 20<\/pre>\n<p>Lots of people ask me what&#8217;s the use of this <code>WHERE 1=1<\/code>.<\/p>\n<\/p>\n<p><!--more--><\/p>\n<p>You know I like to type as little as possible but here I am typing a lot of extra characters. And yet, it makes my development life a lot easier. <\/p>\n<p>If my query has a lot of predicates and I want to see what happens then I usually comment those predicates out by using &#8212; (two dashes). I use my own <a title=\"Comment Line Plug-In for PL\/SQL Developer\" href=\"http:\/\/bar-solutions.com\/software\/plsqldeveloper_plug-ins.html#commentline\" rel=\"nofollow\" target=\"_blank\">CommentLine<\/a> plug-in for this. This is easy for the second and higher predicates. But if I want to comment out the first predicate, then it get a bit harder. Well, not harder, but more work.<\/p>\n<p>If I didn\u2019t use the <code>WHERE 1=1<\/code> and I wanted to comment out the ename predicate then I would have to do something like this:<\/p>\n<pre>SELECT *\r\n  FROM emp e\r\n WHERE \/*e.ename LIKE 'A%'\r\n   AND *\/e.deptno = 20<\/pre>\n<p>I agree, it\u2019s not hard to do, but I think it\u2019s a lot more work than just adding &#8212; (two dashes) in front of a line:<\/p>\n<pre>SELECT *\r\n  FROM emp e\r\n WHERE 1 = 1\r\n--   AND e.ename LIKE 'A%'\r\n   AND e.deptno = 20<\/pre>\n<p>And, as I don\u2019t like typing or at least, I want to make it as easy for me as possible, I am using another one of my plug-ins, <a title=\"Template Plug-In for PL\/SQL Developer\" href=\"http:\/\/bar-solutions.com\/software\/plsqldeveloper_plug-ins.html#template\" rel=\"nofollow\" target=\"_blank\">Template<\/a>, where I defined a template <code>w1<\/code> which results in<\/p>\n<pre>WHERE 1 = 1\r\n   AND <\/pre>\n<p>\n  <br \/>making it easy for me to write the queries.<\/p>\n<p>I think adding this extra predicate has no (or hardly any) influence on the execution time of the query. I think the optimizer ignores this predicate completely.<\/p>\n<p>I hope this explains a bit why I write my queries like this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since some time I have been adding WHERE 1=1 to all my queries. I get queries like this: SELECT * FROM emp e WHERE 1=1 AND e.ename LIKE &#8216;A%&#8217; AND e.deptno = 20 Lots of people ask me what&#8217;s the use of this WHERE 1=1.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,19,9],"tags":[],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-oracle","category-plugins","category-sql"],"_links":{"self":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=624"}],"version-history":[{"count":8,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":633,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions\/633"}],"wp:attachment":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}