Tuesday, October 13, 2009

Creating Joins with the ON Clause

  • The join condition for the natural join is basically an equijoin of all columns with the same name
  • Use the ON clause to specify arbitrary conditions or specify columns to join
  • The join condition is separated from other search conditions
  • The ON clause makes code easy to understand
Retrieving Records with the ON Clause :
  • SELECT e.empno, e.ename, e.deptno, d.deptno, d.loc FROM emp e JOIN dept d ON (e.deptno = d.deptno);

Monday, October 12, 2009

Creating Joins with the USING Clause

  • If several columns have the same names but the data types do not match, the NATURALJOIN clause can be modified with the USING clause to specify the columns that should be used for an equijoin
  • Use the USING clause to match only one column when more than one column matches
  • Do not use a table name or alias in the referenced columns
  • The NATURAL JOIN and USING clauses are mutually exclusive
Joining Column Names :



Retrieving Records with the USING Clause :
  • SELECT emp.empno, emp.ename, dept.loc, deptno FROM emp JOIN dept USIN (deptno) ;

Followers