The
University of Vermont SQL Joins.Whenever you are referencing columns from more than one table, you MUST MUST MUST tell ORACLE which rows from table A go with which rows from table B. By default, RDBMSes assume ALL rows from table A go with EACH row from table B. Hardly ever a meaningful result. Try: SELECT ENAME, DNAME FROM EMP, DEPT; Now try: SELECT ENAME, DNAME FROM EMP, DEPT
? Why did we use put "EMP." and "DEPT." in front of "DEPTNO"? ================================================
Think of a multi-table SELECT. The first thing we want the RDBMS
to do is
So, SELECT * FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO; EMP=
SELECT * FROM EMP, DEPT =
SELF JOIN
FROM EMP A, EMP B
SELECT A.ENAME, B.ENAME
Outer Join
For example:
SELECT A.ENAME, B.ENAME, A.SAL
'KING's record doesn't show because she has no supervisor. Try:
Think of it as (+)= Fill this row in for me with nulls if it is missing. BTW: This is an area of SQL that is less common between different dialects
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Brought
to you through the courtesy of Computing
and Information Technology, University of Vermont. Copyright ©
1996 The University of Vermont and others. All rights reserved.
The University supports both institutional and personal web pages. The views expressed on personal web pages are strictly those of the author, and are not reviewed or approved by the University of Vermont Send questions and comments to Keith.Kennedy@uvm.edu Read the
Webmaster's
Policies.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||