{"id":933,"date":"2005-10-17T12:00:00","date_gmt":"2005-10-17T12:00:00","guid":{"rendered":"http:\/\/orcldoug.com\/blog\/?p=933"},"modified":"2005-10-17T12:00:00","modified_gmt":"2005-10-17T12:00:00","slug":"ansi-join-syntax","status":"publish","type":"post","link":"http:\/\/orcldoug.com\/blog\/2005\/10\/17\/ansi-join-syntax\/","title":{"rendered":"ANSI Join Syntax"},"content":{"rendered":"<p>A couple of days ago one of my colleagues raised the question &#8211; &#8216;ANSI join syntax, does anyone actually <em>use <\/em>that?&#8217; I have pretty strong views on this and so a brief dynamic conversation followed (and that <em>isn&#8217;t <\/em>a euphemism for &#8216;stand-up row&#8217;, I should add!) So, what about ANSI join syntax?<\/p>\n<p>To give the briefest of introductions, from Oracle 9i, instead of using this SQL<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d, emp e<br\/>WHERE d.deptno = e.deptno;<\/pre>\n<p>You can use this<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d JOIN emp e <br\/>USING (deptno);<\/pre>\n<p>Or this<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d JOIN emp e<br\/>ON (d.deptno = e.deptno);<\/pre>\n<p>And instead of this pre-9i outer join<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d, emp e<br\/>WHERE d.deptno = e.deptno (+);<\/pre>\n<p>You can use this<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d LEFT JOIN emp e<br\/>USING (deptno);<\/pre>\n<p>Or this<\/p>\n<pre>SELECT d.dname, e.empno<br\/>FROM dept d LEFT JOIN emp e<br\/>ON (d.deptno = e.deptno);<\/pre>\n<p>(For more info, I googled &#8216;Oracle ANSI join syntax&#8217; and near the top of the results was this <a href=\"http:\/\/www.oreillynet.com\/pub\/a\/network\/2002\/04\/23\/fulljoin.html\">article<\/a> by Sanjay Mishra.)<\/p>\n<p>When Oracle 9i was released I was still teaching for Learning Tree and whenever Oracle released a new major release of the rdbms, new versions of the core courses were developed. One of the key additions to <a href=\"http:\/\/www.learningtree.com\/courses\/590.htm\">the introduction course<\/a> was ANSI join syntax. When I first saw this I thought :-<\/p>\n<p>&#8216;Brilliant! Another thing to learn and what does it give us anyway? Database-independent applications are one of the more dangerous myths still floating around the IT industry. It also looks terribly like that long-winded ugly SQL that MS Access throws at Oracle databases I&#8217;ve supported. Yuck!&#8217;<\/p>\n<p>Of course Oracle included the new syntax in the 9i OCP exam that covers SQL and PL\/SQL, because it\ufffds clearly such a critical part of being a 9i DBA, right? (No further comment.)<\/p>\n<p>Then again, I&#8217;m not at all averse to learning new things and as my job was to help people learn Oracle, I had to review it properly. As I spent more time playing around with it and then teaching it, it occurred to me that I actually quite liked this alternative! The main strengths of ANSI join syntax are<\/p>\n<ul>\n<li>A Full Outer Join is straightforward and easy to understand when looking at the code<\/li>\n<\/ul>\n<ul>\n<li>The join conditions are specified where they make most sense &#8211; in the FROM clause, with the tables that you are joining.<\/li>\n<\/ul>\n<ul>\n<li>Although still possible, it is more unlikely that you will miss one or two join conditions in a long multi-table query. When we were discussing it, my colleague&#8217;s response to this was along the lines of, &#8216;well you wouldn&#8217;t, would you?&#8217; I&#8217;ve had to debug enough long SQL statements with missing join conditions to prove this wrong. The problem is that there is absolutely no proper placement for join conditions in Oracle&#8217;s original syntax. They can appear anywhere in the where clause, in any order, all mixed in with business logic predicates. Of course, <em>good <\/em>SQL developers impose some ordering themselves, to make their queries more readable and maintainable, but there&#8217;s nothing to force them to do this. The punch-line is that it&#8217;s not the <em>good <\/em>SQL developers who make the most mistakes <script data-pagespeed-no-defer=\"\" type=\"text\/javascript\">\/\/<![CDATA[\n(function(){for(var g=\"function\"==typeof Object.defineProperties?Object.defineProperty:function(b,c,a){if(a.get||a.set)throw new TypeError(\"ES3 does not support getters and setters.\");b!=Array.prototype&#038;&#038;b!=Object.prototype&#038;&#038;(b[c]=a.value)},h=\"undefined\"!=typeof window&#038;&#038;window===this?this:\"undefined\"!=typeof global&#038;&#038;null!=global?global:this,k=[\"String\",\"prototype\",\"repeat\"],l=0;l<k.length-1;l++){var m=k[l];m in h||(h[m]={});h=h[m]}var n=k[k.length-1],p=h[n],q=p?p:function(b){var c;if(null==this)throw new TypeError(\"The 'this' value for String.prototype.repeat must not be null or undefined\");c=this+\"\";if(0>b||1342177279<b)throw new RangeError(\"Invalid count value\");b|=0;for(var a=\"\";b;)if(b&#038;1&#038;&#038;(a+=c),b>>>=1)c+=c;return a};q!=p&&null!=q&&g(h,n,{configurable:!0,writable:!0,value:q});var t=this;function u(b,c){var a=b.split(\".\"),d=t;a[0]in d||!d.execScript||d.execScript(\"var \"+a[0]);for(var e;a.length&&(e=a.shift());)a.length||void 0===c?d[e]?d=d[e]:d=d[e]={}:d[e]=c};function v(b){var c=b.length;if(0<c){for(var a=Array(c),d=0;d<c;d++)a[d]=b[d];return a}return[]};function w(b){var c=window;if(c.addEventListener)c.addEventListener(\"load\",b,!1);else if(c.attachEvent)c.attachEvent(\"onload\",b);else{var a=c.onload;c.onload=function(){b.call(this);a&#038;&#038;a.call(this)}}};var x;function y(b,c,a,d,e){this.h=b;this.j=c;this.l=a;this.f=e;this.g={height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};this.i=d;this.b={};this.a=[];this.c={}}function z(b,c){var a,d,e=c.getAttribute(\"data-pagespeed-url-hash\");if(a=e&#038;&#038;!(e in b.c))if(0>=c.offsetWidth&&0>=c.offsetHeight)a=!1;else{d=c.getBoundingClientRect();var f=document.body;a=d.top+(\"pageYOffset\"in window?window.pageYOffset:(document.documentElement||f.parentNode||f).scrollTop);d=d.left+(\"pageXOffset\"in window?window.pageXOffset:(document.documentElement||f.parentNode||f).scrollLeft);f=a.toString()+\",\"+d;b.b.hasOwnProperty(f)?a=!1:(b.b[f]=!0,a=a<=b.g.height&#038;&#038;d<=b.g.width)}a&#038;&#038;(b.a.push(e),b.c[e]=!0)}y.prototype.checkImageForCriticality=function(b){b.getBoundingClientRect&#038;&#038;z(this,b)};u(\"pagespeed.CriticalImages.checkImageForCriticality\",function(b){x.checkImageForCriticality(b)});u(\"pagespeed.CriticalImages.checkCriticalImages\",function(){A(x)});function A(b){b.b={};for(var c=[\"IMG\",\"INPUT\"],a=[],d=0;d<c.length;++d)a=a.concat(v(document.getElementsByTagName(c[d])));if(a.length&#038;&#038;a[0].getBoundingClientRect){for(d=0;c=a[d];++d)z(b,c);a=\"oh=\"+b.l;b.f&#038;&#038;(a+=\"&#038;n=\"+b.f);if(c=!!b.a.length)for(a+=\"&#038;ci=\"+encodeURIComponent(b.a[0]),d=1;d<b.a.length;++d){var e=\",\"+encodeURIComponent(b.a[d]);131072>=a.length+e.length&&(a+=e)}b.i&&(e=\"&rd=\"+encodeURIComponent(JSON.stringify(B())),131072>=a.length+e.length&&(a+=e),c=!0);C=a;if(c){d=b.h;b=b.j;var f;if(window.XMLHttpRequest)f=new XMLHttpRequest;else if(window.ActiveXObject)try{f=new ActiveXObject(\"Msxml2.XMLHTTP\")}catch(r){try{f=new ActiveXObject(\"Microsoft.XMLHTTP\")}catch(D){}}f&&(f.open(\"POST\",d+(-1==d.indexOf(\"?\")?\"?\":\"&\")+\"url=\"+encodeURIComponent(b)),f.setRequestHeader(\"Content-Type\",\"application\/x-www-form-urlencoded\"),f.send(a))}}}function B(){var b={},c;c=document.getElementsByTagName(\"IMG\");if(!c.length)return{};var a=c[0];if(!(\"naturalWidth\"in a&&\"naturalHeight\"in a))return{};for(var d=0;a=c[d];++d){var e=a.getAttribute(\"data-pagespeed-url-hash\");e&&(!(e in b)&&0<a.width&#038;&#038;0<a.height&#038;&#038;0<a.naturalWidth&#038;&#038;0<a.naturalHeight||e in b&#038;&#038;a.width>=b[e].o&&a.height>=b[e].m)&&(b[e]={rw:a.width,rh:a.height,ow:a.naturalWidth,oh:a.naturalHeight})}return b}var C=\"\";u(\"pagespeed.CriticalImages.getBeaconData\",function(){return C});u(\"pagespeed.CriticalImages.Run\",function(b,c,a,d,e,f){var r=new y(b,c,a,e,f);x=r;d&&w(function(){window.setTimeout(function(){A(r)},0)})});})();pagespeed.CriticalImages.Run('\/mod_pagespeed_beacon','http:\/\/orcldoug.com\/blog\/?p=933','2L-ZMDIrHf',true,false,'W8eh1wZo64E');\n\/\/]]><\/script><img decoding=\"async\" alt=\";-)\" class=\"emoticon\" data-pagespeed-url-hash=\"2200056678\" onload=\"pagespeed.CriticalImages.checkImageForCriticality(this);\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAA1VBMVEUzM2a9pUL90Bzp2JqDcEL\/7J\/uwhKihjD\/9cz93FiEg3utoopSTmjgxV+ckWT\/1zn65pRsbGz\/8LX\/+uSkoav9ywP\/5HaVjGpGRGiJgXxeXYD16LeAdWrPt2D80iz\/7qz\/+Nytpp3RwImdk4f\/20z\/6I1oZ4j\/88T\/\/fOkoav7zBD\/5oQ9O2fGqTrn3LWLdT\/\/7aX1xwuliS7\/9tP\/4muDg4OtpJRXU2vnzWr\/2kdtaHv\/8br\/++z8zAr\/5X9NS2+LhnZjYob70zOhlX7\/6pahobYAAADhciW9AAAAR3RSTlP\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/AMecVm8AAADTSURBVBjTLY+LboJAEEVHqwj4oAXHt+5asRjxsQir0oJW1P3\/T3LYeJJJ5p5kkrmgSrBEbwpoDrWEsbqV41scoJt5PA5YgVo04LnSwhWzqBT77uo28rg5PzbDfKsAkyz7GfHYBIBlYZAQnkcHZuCyR+jjPyDjPKb8x+rLno99wIdJUBbfcHZwCGgFwW7sMvH51bKqhgSVC\/f3umjeT5tpihUSWIiP4RUGk3aaR3b5Kc7C8NJLrHSNHam7RFj4vlPFiLIWamtQWaNiy3dbwu7YUurtBZssKHzU1V8eAAAAAElFTkSuQmCC\" style=\"display: inline; vertical-align: bottom\"\/><\/li>\n<\/ul>\n<p>And the Cons?<\/p>\n<ul>\n<li>Depending on the number of tables being joined, the join conditions and the particular variation of the syntax that you use, the ANSI approach can be verbose and lead to more typing. (This is probably the one that put me off most at first.)<\/li>\n<\/ul>\n<ul>\n<li>It&#8217;s only available from 9i so if you are working with earlier versions (which many of us are, regardless of what may or may not be <em>supported<\/em>) then you would need to chop-and-change between methods. (This is the probably the biggest down-side for me now)<\/li>\n<\/ul>\n<ul>\n<li>I, my colleagues and most other Oracle developers and DBAs are far more familiar and comfortable with the traditional Oracle approach. (I&#8217;m sure that this is the number one reason why most people I know still use the Oracle syntax!)<\/li>\n<\/ul>\n<p>When you look at it, the Pros seem to be more tangible than the Cons. I struggle to defend the traditional Oracle join syntax versus the ANSI syntax. As you can imagine, I&#8217;ve moved over to ANSI syntax whenever I&#8217;m using a version &gt; 9i.<\/p>\n<p>Of course, I haven&#8217;t <img decoding=\"async\" alt=\";-)\" class=\"emoticon\" data-pagespeed-url-hash=\"2200056678\" onload=\"pagespeed.CriticalImages.checkImageForCriticality(this);\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAA1VBMVEUzM2a9pUL90Bzp2JqDcEL\/7J\/uwhKihjD\/9cz93FiEg3utoopSTmjgxV+ckWT\/1zn65pRsbGz\/8LX\/+uSkoav9ywP\/5HaVjGpGRGiJgXxeXYD16LeAdWrPt2D80iz\/7qz\/+Nytpp3RwImdk4f\/20z\/6I1oZ4j\/88T\/\/fOkoav7zBD\/5oQ9O2fGqTrn3LWLdT\/\/7aX1xwuliS7\/9tP\/4muDg4OtpJRXU2vnzWr\/2kdtaHv\/8br\/++z8zAr\/5X9NS2+LhnZjYob70zOhlX7\/6pahobYAAADhciW9AAAAR3RSTlP\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/AMecVm8AAADTSURBVBjTLY+LboJAEEVHqwj4oAXHt+5asRjxsQir0oJW1P3\/T3LYeJJJ5p5kkrmgSrBEbwpoDrWEsbqV41scoJt5PA5YgVo04LnSwhWzqBT77uo28rg5PzbDfKsAkyz7GfHYBIBlYZAQnkcHZuCyR+jjPyDjPKb8x+rLno99wIdJUBbfcHZwCGgFwW7sMvH51bKqhgSVC\/f3umjeT5tpihUSWIiP4RUGk3aaR3b5Kc7C8NJLrHSNHam7RFj4vlPFiLIWamtQWaNiy3dbwu7YUurtBZssKHzU1V8eAAAAAElFTkSuQmCC\" style=\"display: inline; vertical-align: bottom\"\/><\/p>\n<p>Any other opinions on this?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of days ago one of my colleagues raised the question &#8211; &#8216;ANSI join syntax, does anyone actually use that?&#8217; I have pretty strong views on this and so a brief dynamic conversation followed (and that isn&#8217;t a euphemism for &#8216;stand-up row&#8217;, I should add!) So, what about ANSI join syntax? To give the&hellip; <a class=\"more-link\" href=\"http:\/\/orcldoug.com\/blog\/2005\/10\/17\/ansi-join-syntax\/\">Continue reading <span class=\"screen-reader-text\">ANSI Join Syntax<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-933","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":968,"url":"http:\/\/orcldoug.com\/blog\/2005\/07\/22\/deferred-constraint-checking\/","url_meta":{"origin":933,"position":0},"title":"Deferred Constraint Checking","date":"July 22, 2005","format":false,"excerpt":"In my previous blog entry I highlighted a few of the reasons that integrity constraint checking should not be deferred, stated by Date in his recent book (and by him and others in other papers). At the time and while looking at an entry over on Jeff Hunter's Blog I\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":938,"url":"http:\/\/orcldoug.com\/blog\/2005\/09\/29\/html-db\/","url_meta":{"origin":933,"position":1},"title":"HTML DB","date":"September 29, 2005","format":false,"excerpt":"Today I had one of those minor buzzes of excitement when I started to play around with Oracle's hosted HTML DB environment.Without wanting to go into my current feelings about work, you could say things are a little quiet. I'm trying to find things to do but I've joined just\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1555,"url":"http:\/\/orcldoug.com\/blog\/2009\/12\/18\/bug-hunting\/","url_meta":{"origin":933,"position":2},"title":"Bug Hunting","date":"December 18, 2009","format":false,"excerpt":"It's early days but I think I became the joint father of a bug report this week. This is bug number 9219636. SQL> CREATE TYPE INTEGER_ARRAY_T AS TABLE OF INTEGER \u00a0 2\u00a0 \/ Type created. SQL> SQL> CREATE TABLE V_SESSION_VALID ( \u00a0 2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SID NUMBER , \u00a0 3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SESSION_ID NUMBER\u2026","rel":"","context":"With 8 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1386,"url":"http:\/\/orcldoug.com\/blog\/2008\/02\/27\/optimiser-upgrading-from-9i-to-10g\/","url_meta":{"origin":933,"position":3},"title":"Optimiser &#8211; Upgrading from 9i to 10g","date":"February 27, 2008","format":false,"excerpt":"On the one hand, I regret the fact I seem to be posting a lot of links to other people's work at the moment but I couldn't let this one by, if only for those who don't use OraNA or the like and might miss it.The one consistent message I\u2026","rel":"","context":"With 15 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":866,"url":"http:\/\/orcldoug.com\/blog\/2006\/02\/08\/updates\/","url_meta":{"origin":933,"position":4},"title":"Updates","date":"February 8, 2006","format":false,"excerpt":"Just a couple of small updates on some previous blogs.The database that was suffering from network latency problems between it and the app servers was moved down South last week. It all went very smoothly and that particular problem has been resolved. The 20+ hour job runs over night very\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1162,"url":"http:\/\/orcldoug.com\/blog\/2006\/12\/13\/despicable\/","url_meta":{"origin":933,"position":5},"title":"Despicable","date":"December 13, 2006","format":false,"excerpt":"Here's a top tip for anyone who I might interview for a DBA job in future, based on three consecutive interviews for my replacement I just overheard.If you really don't know the name of the package you use to collect object statistics for the cost based optimiser in 9i, you're\u2026","rel":"","context":"With 56 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/comments?post=933"}],"version-history":[{"count":0,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/933\/revisions"}],"wp:attachment":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/media?parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/categories?post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/tags?post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}