Using two columns during table join : USING « Table Joins « Oracle PL/SQL Tutorial

Home
Oracle PL/SQL Tutorial
1.Introduction
2.Query Select
3.Set
4.Insert Update Delete
5.Sequences
6.Table
7.Table Joins
8.View
9.Index
10.SQL Data Types
11.Character String Functions
12.Aggregate Functions
13.Date Timestamp Functions
14.Numerical Math Functions
15.Conversion Functions
16.Analytical Functions
17.Miscellaneous Functions
18.Regular Expressions Functions
19.Statistical Functions
20.Linear Regression Functions
21.PL SQL Data Types
22.PL SQL Statements
23.PL SQL Operators
24.PL SQL Programming
25.Cursor
26.Collections
27.Function Procedure Packages
28.Trigger
29.SQL PLUS Session Environment
30.System Tables Data Dictionary
31.System Packages
32.Object Oriented
33.XML
34.Large Objects
35.Transaction
36.User Privilege
Oracle PL/SQL Tutorial » Table Joins » USING 
7.14.3.Using two columns during table join
SQL>
SQL>
SQL>
SQL> create table course_schedule
  2  course     VARCHAR2(6)
  3  , begindate  DATE
  4  , trainer    NUMBER(4)
  5  , location   VARCHAR2(20)) ;

Table created.

SQL>
SQL>
SQL> insert into course_schedule values ('SQL',date '1999-04-12',1,'VANCOUVER' );

row created.

SQL> insert into course_schedule values ('OAU',date '1999-08-10',2,'CHICAGO');

row created.

SQL> insert into course_schedule values ('SQL',date '1999-10-04',3,'SEATTLE');

row created.

SQL> insert into course_schedule values ('SQL',date '1999-12-13',4,'DALLAS' );

row created.

SQL> insert into course_schedule values ('JAV',date '1999-12-13',5,'SEATTLE');

row created.

SQL> insert into course_schedule values ('XML',date '2000-02-03',6,'VANCOUVER' );

row created.

SQL> insert into course_schedule values ('JAV',date '2000-02-01',7,'DALLAS' );

row created.

SQL> insert into course_schedule values ('PLS',date '2000-09-11',8,'VANCOUVER' );

row created.

SQL> insert into course_schedule values ('XML',date '2000-09-18',NULL,'SEATTLE');

row created.

SQL> insert into course_schedule values ('OAU',date '2000-09-27',9,'DALLAS' );

row created.

SQL> insert into course_schedule values ('ERM',date '2001-01-15',10, NULL    );

row created.

SQL> insert into course_schedule values ('PRO',date '2001-02-19',NULL,'VANCOUVER' );

row created.

SQL> insert into course_schedule values ('RSD',date '2001-02-24',8,'CHICAGO');

row created.

SQL>
SQL>
SQL> create table registrations
  2  attendee    NUMBER(4)
  3  , course      VARCHAR2(6)
  4  , begindate   DATE
  5  , evaluation  NUMBER(1)) ;

Table created.

SQL>
SQL>
SQL> insert into registrations values (1'SQL',date '1999-04-12',4   );

row created.

SQL> insert into registrations values (2'SQL',date '1999-12-13',NULL);

row created.

SQL> insert into registrations values (3'SQL',date '1999-12-13',NULL);

row created.

SQL> insert into registrations values (4'OAU',date '1999-08-10',4   );

row created.

SQL> insert into registrations values (5'OAU',date '2000-09-27',5   );

row created.

SQL> insert into registrations values (6'JAV',date '1999-12-13',2   );

row created.

SQL> insert into registrations values (7'JAV',date '2000-02-01',4   );

row created.

SQL> insert into registrations values (8'JAV',date '2000-02-01',5   );

row created.

SQL> insert into registrations values (9'XML',date '2000-02-03',4   );

row created.

SQL> insert into registrations values (10,'XML',date '2000-02-03',5   );

row created.

SQL> insert into registrations values (1'PLS',date '2000-09-11',NULL);

row created.

SQL> insert into registrations values (2'PLS',date '2000-09-11',NULL);

row created.

SQL> insert into registrations values (3'PLS',date '2000-09-11',NULL);

row created.

SQL>
SQL>
SQL>
SQL> select o.trainer, avg(r.evaluation)
  2  from   course_schedule o
  3         join
  4         registrations r
  5         using (course,begindate)
  6  group  by o.trainer;

   TRAINER AVG(R.EVALUATION)
---------- -----------------
         1                 4
         6               4.5
         2                 4
         4
         5                 2
         8
         7               4.5
         9                 5

rows selected.

SQL>
SQL> drop table course_schedule;

Table dropped.

SQL>
SQL> drop table registrations;

Table dropped.

SQL>
SQL>
7.14.USING
7.14.1.Simplifying Joins with the USING Keyword
7.14.2.Using clause for table join
7.14.3.Using two columns during table join
7.14.4.Join table using
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.