Oracle PL/SQL Tutorial/Table Joins/Introduction

Материал из SQL эксперт
Перейти к: навигация, поиск

autotrace ansi full outer join

SQL>
SQL>
SQL> create table myTable as
  2  select  "myTable" as C1
  3   ,OBJECT_NAME
  4   ,SUBOBJECT_NAME
  5   ,OBJECT_ID
  6   ,DATA_OBJECT_ID
  7   ,OBJECT_TYPE
  8   ,CREATED
  9   ,LAST_DDL_TIME
 10   ,TIMESTAMP
 11   ,STATUS
 12   ,TEMPORARY
 13   ,GENERATED
 14   ,SECONDARY
 15  from dba_objects;
Table created.
SQL>
SQL> create table myTable2 as
  2  select  "myTable2" as C1
  3   ,OBJECT_NAME  || "myTable2" as object_name
  4   ,SUBOBJECT_NAME
  5   ,OBJECT_ID
  6   ,DATA_OBJECT_ID
  7   ,OBJECT_TYPE
  8   ,CREATED
  9   ,LAST_DDL_TIME
 10   ,TIMESTAMP
 11   ,STATUS
 12   ,TEMPORARY
 13   ,GENERATED
 14   ,SECONDARY
 15  from dba_objects
 16  where rownum <= 10000;
Table created.
SQL>
SQL> create index myTable_object_id on myTable (object_id);
Index created.
SQL>
SQL> create index myTable2_object_id on myTable2 (object_id);
Index created.
SQL>
SQL> analyze table myTable compute statistics;
Table analyzed.
SQL>
SQL> analyze table myTable2 compute statistics;
Table analyzed.
SQL>
SQL> set autotrace TRACEONLY
SQL> set timing on
SQL> select *
  2  from myTable a, myTable2 b
  3  where a.object_id = b.object_id(+)
  4  union
  5  select *
  6  from myTable a, myTable2 b
  7  where a.object_id(+) = b.object_id;
13158 rows selected.
Elapsed: 00:00:00.62
Execution Plan
----------------------------------------------------------
Plan hash value: 4186416997
---------------------------------------------------------------------------------------------
| Id  | Operation                      | Name               | Rows  | Bytes |TempSpc| Cost  |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                    | 23158 |  4296K|       | 47039 |
|   1 |  SORT UNIQUE                   |                    | 23158 |  4296K|    10M| 47039 |
|   2 |   UNION-ALL                    |                    |       |       |       |       |
|   3 |    NESTED LOOPS OUTER          |                    | 13158 |  2441K|       | 26343 |
|   4 |     TABLE ACCESS FULL          | MYTABLE            | 13158 |  1169K|       |    27 |
|   5 |     TABLE ACCESS BY INDEX ROWID| MYTABLE2           |     1 |    99 |       |     2 |
|*  6 |      INDEX RANGE SCAN          | MYTABLE2_OBJECT_ID |     1 |       |       |     1 |
|   7 |    NESTED LOOPS OUTER          |                    | 10000 |  1855K|       | 20022 |
|   8 |     TABLE ACCESS FULL          | MYTABLE2           | 10000 |   966K|       |    22 |
|   9 |     TABLE ACCESS BY INDEX ROWID| MYTABLE            |     1 |    91 |       |     2 |
|* 10 |      INDEX RANGE SCAN          | MYTABLE_OBJECT_ID  |     1 |       |       |     1 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access("A"."OBJECT_ID"="B"."OBJECT_ID"(+))
  10 - access("A"."OBJECT_ID"(+)="B"."OBJECT_ID")
Note
-----
   - cpu costing is off (consider enabling it)

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
      43520  consistent gets
          0  physical reads
          0  redo size
    1301014  bytes sent via SQL*Net to client
      10027  bytes received via SQL*Net from client
        879  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
      13158  rows processed
SQL>
SQL>
SQL> select *
  2  from myTable a full outer join myTable2 b
  3  using (object_id);
13158 rows selected.
Elapsed: 00:00:00.52
Execution Plan
----------------------------------------------------------
Plan hash value: 3236823177
-------------------------------------------------------------------------------------
| Id  | Operation                      | Name               | Rows  | Bytes | Cost  |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                    | 13658 |  4401K| 26365 |
|   1 |  VIEW                          |                    | 13658 |  4401K| 26365 |
|   2 |   UNION-ALL                    |                    |       |       |       |
|   3 |    NESTED LOOPS OUTER          |                    | 13158 |  2441K| 26343 |
|   4 |     TABLE ACCESS FULL          | MYTABLE            | 13158 |  1169K|    27 |
|   5 |     TABLE ACCESS BY INDEX ROWID| MYTABLE2           |     1 |    99 |     2 |
|*  6 |      INDEX RANGE SCAN          | MYTABLE2_OBJECT_ID |     1 |       |     1 |
|*  7 |    FILTER                      |                    |       |       |       |
|   8 |     TABLE ACCESS FULL          | MYTABLE2           |   500 | 49500 |    22 |
|*  9 |     INDEX RANGE SCAN           | MYTABLE_OBJECT_ID  |     1 |    13 |     1 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access("A"."OBJECT_ID"="B"."OBJECT_ID"(+))
   7 - filter( NOT EXISTS (SELECT /*+ UNNEST */ 0 FROM "MYTABLE" "A" WHERE
              "A"."OBJECT_ID"=:B1))
   9 - access("A"."OBJECT_ID"=:B1)
Note
-----
   - cpu costing is off (consider enabling it)

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
      45912  consistent gets
          0  physical reads
          0  redo size
     956084  bytes sent via SQL*Net to client
      10027  bytes received via SQL*Net from client
        879  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
      13158  rows processed
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
SQL>
SQL> drop table myTable;
Table dropped.
SQL>
SQL> drop table myTable2;
Table dropped.


Convert subqueries to JOINs

SQL>
SQL> CREATE TABLE emps (
  2    emp varchar(30)
  3   ,title    varchar(30)
  4  );
Table created.
SQL>
SQL> INSERT INTO emps VALUES ("Tom","Programmer");
1 row created.
SQL> INSERT INTO emps VALUES ("Jack","Tester");
1 row created.
SQL> INSERT INTO emps VALUES ("Mary","Technician");
1 row created.
SQL>
SQL> CREATE TABLE JobLevel (
  2    title     varchar(30)
  3   ,rank    varchar(30)
  4  );
Table created.
SQL>
SQL> INSERT INTO JobLevel VALUES ("Programmer","Level1");
1 row created.
SQL> INSERT INTO JobLevel VALUES ("Tester","Level2");
1 row created.
SQL> INSERT INTO JobLevel VALUES ("Technician","Level3");
1 row created.
SQL>
SQL> CREATE TABLE salary (
  2    rank     varchar(30)
  3   ,payment  DECIMAL(10,2)
  4  );
Table created.
SQL>
SQL> INSERT INTO salary VALUES ("Level1",2000.00);
1 row created.
SQL> INSERT INTO salary VALUES ("Level2",3000.00);
1 row created.
SQL> INSERT INTO salary VALUES ("Level3",5000.00);
1 row created.
SQL> INSERT INTO salary VALUES ("Level4",6000.00);
1 row created.
SQL>
SQL> select * from emps;

EMP
------------------------------
TITLE
------------------------------
Tom
Programmer
Jack
Tester
Mary
Technician
3 rows selected.
SQL> select * from JobLevel;

TITLE
------------------------------
RANK
------------------------------
Programmer
Level1
Tester
Level2
Technician
Level3

3 rows selected.
SQL> select * from salary;

RANK                               PAYMENT
------------------------------  ----------
Level1                                2000
Level2                                3000
Level3                                5000
Level4                                6000

4 rows selected.
SQL>
SQL> SELECT payment FROM salary WHERE rank =
  2    (SELECT rank FROM JobLevel WHERE title =
  3      (SELECT title FROM emps WHERE emp = "Jack"));

   PAYMENT
----------
      3000
1 row selected.
SQL>
SQL>
SQL>
SQL> DROP TABLE emps;
Table dropped.
SQL> DROP TABLE JobLevel;
Table dropped.
SQL> DROP TABLE salary;
Table dropped.
SQL>


Example simple join.

SQL>
SQL>
SQL> CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
  2                    ENAME VARCHAR2(10),
  3                    JOB VARCHAR2(9),
  4                    MGR NUMBER(4),
  5                    HIREDATE DATE,
  6                    SAL NUMBER(7, 2),
  7                    COMM NUMBER(7, 2),
  8                    DEPTNO NUMBER(2));
Table created.
SQL>
SQL> INSERT INTO EMP VALUES (7369, "SMITH", "CLERK",    7902, TO_DATE("17-DEC-1980", "DD-MON-YYYY"), 800, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7499, "ALLEN", "SALESMAN", 7698, TO_DATE("20-FEB-1981", "DD-MON-YYYY"), 1600, 300, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7521, "WARD",  "SALESMAN", 7698, TO_DATE("22-FEB-1981", "DD-MON-YYYY"), 1250, 500, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7566, "JONES", "MANAGER",  7839, TO_DATE("2-APR-1981",  "DD-MON-YYYY"), 2975, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7654, "MARTIN", "SALESMAN", 7698,TO_DATE("28-SEP-1981", "DD-MON-YYYY"), 1250, 1400, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7698, "BLAKE", "MANAGER", 7839,TO_DATE("1-MAY-1981", "DD-MON-YYYY"), 2850, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7782, "CLARK", "MANAGER", 7839,TO_DATE("9-JUN-1981", "DD-MON-YYYY"), 2450, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7788, "SCOTT", "ANALYST", 7566,TO_DATE("09-DEC-1982", "DD-MON-YYYY"), 3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7839, "KING", "PRESIDENT", NULL,TO_DATE("17-NOV-1981", "DD-MON-YYYY"), 5000, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7844, "TURNER", "SALESMAN", 7698,TO_DATE("8-SEP-1981", "DD-MON-YYYY"), 1500, 0, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7876, "ADAMS", "CLERK", 7788,TO_DATE("12-JAN-1983", "DD-MON-YYYY"), 1100, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7900, "JAMES", "CLERK", 7698,TO_DATE("3-DEC-1981", "DD-MON-YYYY"), 950, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7902, "FORD", "ANALYST", 7566,TO_DATE("3-DEC-1981", "DD-MON-YYYY"), 3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7934, "MILLER", "CLERK", 7782,TO_DATE("23-JAN-1982", "DD-MON-YYYY"), 1300, NULL, 10);
1 row created.
SQL>
SQL> CREATE TABLE DEPT (DEPTNO NUMBER(2),DNAME VARCHAR2(14),LOC VARCHAR2(13) );
Table created.
SQL>
SQL> INSERT INTO DEPT VALUES (10, "ACCOUNTING", "NEW YORK");
1 row created.
SQL> INSERT INTO DEPT VALUES (20, "RESEARCH", "DALLAS");
1 row created.
SQL> INSERT INTO DEPT VALUES (30, "SALES", "CHICAGO");
1 row created.
SQL> INSERT INTO DEPT VALUES (40, "OPERATIONS", "BOSTON");
1 row created.
SQL>
SQL> select * from emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
14 rows selected.
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
SQL>
SQL>
SQL> select d.deptno, d.dname, e.empno, e.sal, e.rum
  2  from   dept d, emp e
  3  where  d.deptno=e.deptno;
    DEPTNO DNAME               EMPNO        SAL       COMM
---------- -------------- ---------- ---------- ----------
        20 RESEARCH             7369        800
        30 SALES                7499       1600        300
        30 SALES                7521       1250        500
        20 RESEARCH             7566       2975
        30 SALES                7654       1250       1400
        30 SALES                7698       2850
        10 ACCOUNTING           7782       2450
        20 RESEARCH             7788       3000
        10 ACCOUNTING           7839       5000
        30 SALES                7844       1500          0
        20 RESEARCH             7876       1100
        30 SALES                7900        950
        20 RESEARCH             7902       3000
        10 ACCOUNTING           7934       1300
14 rows selected.
SQL>
SQL> drop table emp;
Table dropped.
SQL>
SQL> drop table dept;
Table dropped.
SQL>


Performing SELECT Statements that Use More than Two Tables

Joins can be used to connect any number of tables.

The number of joins you will need in your WHERE clause is total_number_of_tables - 1

There are two types of join conditions, which are based on the operator.

Equijoins - You use the equality operator (=) in the join.

Non-equijoins - You use an operator other than equals in the join, such as <, >, BETWEEN, and so on.

7. 1. Introduction 7. 1. 1. Performing SELECT Statements that Use More than Two Tables 7. 1. 2. <A href="/Tutorial/Oracle/0140__Table-Joins/Threedifferenttypesofjoins.htm">Three different types of joins:</a> 7. 1. 3. <A href="/Tutorial/Oracle/0140__Table-Joins/UnderstandingNonequijoins.htm">Understanding Non-equijoins</a> 7. 1. 4. <A href="/Tutorial/Oracle/0140__Table-Joins/PerformingSELECTStatementsthatUseTwoTables.htm">Performing SELECT Statements that Use Two Tables</a> 7. 1. 5. <A href="/Tutorial/Oracle/0140__Table-Joins/Examplesimplejoin.htm">Example simple join.</a> 7. 1. 6. <A href="/Tutorial/Oracle/0140__Table-Joins/Usetablealiasintablejoin.htm">Use table alias in table join</a> 7. 1. 7. <A href="/Tutorial/Oracle/0140__Table-Joins/ConvertsubqueriestoJOINs.htm">Convert subqueries to JOINs</a> 7. 1. 8. <A href="/Tutorial/Oracle/0140__Table-Joins/autotraceansifullouterjoin.htm">autotrace ansi full outer join</a>

Performing SELECT Statements that Use Two Tables

To join two tables means that you specify both the tables in the query"s FROM clause.

And Use related columns from each table.

The related columns could be a foreign key from one table and the primary key from another table.

You use an operator, such as the equality operator (=), in the query"s WHERE clause.



SQL> -- create demo table
SQL> create table Employee(
  2    EMPNO         NUMBER(3),
  3    ENAME         VARCHAR2(15 BYTE),
  4    HIREDATE      DATE,
  5    ORIG_SALARY   NUMBER(6),
  6    CURR_SALARY   NUMBER(6),
  7    REGION        VARCHAR2(1 BYTE)
  8  )
  9  /
Table created.
SQL>
SQL> create table job (
  2    EMPNO         NUMBER(3),
  3    jobtitle      VARCHAR2(20 BYTE)
  4  )
  5  /
Table created.
SQL>
SQL> insert into job (EMPNO, Jobtitle) values (1,"Tester");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (2,"Accountant");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (3,"Developer");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (4,"COder");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (5,"Director");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (6,"Mediator");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (7,"Proffessor");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (8,"Programmer");
1 row created.
SQL> insert into job (EMPNO, Jobtitle) values (9,"Developer");
1 row created.
SQL>
SQL>
SQL> -- prepare data
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (1,      "Jason", to_date("19960725","YYYYMMDD"), 1234,              8767,         "E")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (2,      "John",  to_date("19970715","YYYYMMDD"), 2341,              3456,         "W")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (3,      "Joe",   to_date("19860125","YYYYMMDD"), 4321,              5654,         "E")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (4,      "Tom",   to_date("20060913","YYYYMMDD"), 2413,              6787,         "W")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (5,      "Jane",  to_date("20050417","YYYYMMDD"), 7654,              4345,         "E")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (6,      "James", to_date("20040718","YYYYMMDD"), 5679,              6546,         "W")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (7,      "Jodd",  to_date("20030720","YYYYMMDD"), 5438,              7658,         "E")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (8,      "Joke",  to_date("20020101","YYYYMMDD"), 8765,              4543,         "W")
  3  /
1 row created.
SQL> insert into Employee(EMPNO,  EName,   HIREDATE,                       ORIG_SALARY,       CURR_SALARY,  REGION)
  2               values (9,      "Jack",  to_date("20010829","YYYYMMDD"), 7896,              1232,         "E")
  3  /
1 row created.
SQL>
SQL>
SQL>
SQL> -- display data in the table
SQL> select * from Employee
  2  /
     EMPNO ENAME           HIREDATE  ORIG_SALARY CURR_SALARY R
---------- --------------- --------- ----------- ----------- -
         1 Jason           25-JUL-96        1234        8767 E
         2 John            15-JUL-97        2341        3456 W
         3 Joe             25-JAN-86        4321        5654 E
         4 Tom             13-SEP-06        2413        6787 W
         5 Jane            17-APR-05        7654        4345 E
         6 James           18-JUL-04        5679        6546 W
         7 Jodd            20-JUL-03        5438        7658 E
         8 Joke            01-JAN-02        8765        4543 W
         9 Jack            29-AUG-01        7896        1232 E
9 rows selected.
SQL> select * from job
  2  /
     EMPNO JOBTITLE
---------- --------------------
         1 Tester
         2 Accountant
         3 Developer
         4 COder
         5 Director
         6 Mediator
         7 Proffessor
         8 Programmer
         9 Developer
9 rows selected.
SQL>
SQL>
SQL> SELECT employee.ename, job.jobtitle
  2  FROM employee, job
  3  WHERE employee.empno = job.empno;
ENAME           JOBTITLE
--------------- --------------------
Jason           Tester
John            Accountant
Joe             Developer
Tom             COder
Jane            Director
James           Mediator
Jodd            Proffessor
Joke            Programmer
Jack            Developer
9 rows selected.
SQL>
SQL>
SQL> -- clean the table
SQL> drop table Employee
  2  /
Table dropped.
SQL> drop table job
  2  /
Table dropped.
SQL>


Three different types of joins:

Inner joins - Return a row only when the columns in the join contain values that satisfy the join condition.

This means that if a row has a null value in one of the columns in the join condition, that row isn"t returned.

Outer joins - Can return a row even when one of the columns in the join condition contains a null value.

Self joins - Return rows joined on the same table.

7. 1. Introduction 7. 1. 1. <A href="/Tutorial/Oracle/0140__Table-Joins/PerformingSELECTStatementsthatUseMorethanTwoTables.htm">Performing SELECT Statements that Use More than Two Tables</a> 7. 1. 2. Three different types of joins: 7. 1. 3. <A href="/Tutorial/Oracle/0140__Table-Joins/UnderstandingNonequijoins.htm">Understanding Non-equijoins</a> 7. 1. 4. <A href="/Tutorial/Oracle/0140__Table-Joins/PerformingSELECTStatementsthatUseTwoTables.htm">Performing SELECT Statements that Use Two Tables</a> 7. 1. 5. <A href="/Tutorial/Oracle/0140__Table-Joins/Examplesimplejoin.htm">Example simple join.</a> 7. 1. 6. <A href="/Tutorial/Oracle/0140__Table-Joins/Usetablealiasintablejoin.htm">Use table alias in table join</a> 7. 1. 7. <A href="/Tutorial/Oracle/0140__Table-Joins/ConvertsubqueriestoJOINs.htm">Convert subqueries to JOINs</a> 7. 1. 8. <A href="/Tutorial/Oracle/0140__Table-Joins/autotraceansifullouterjoin.htm">autotrace ansi full outer join</a>

Understanding Non-equijoins

A non-equijoin uses an operator other than the equality operator in the join.

Examples of non-equality operators are:

  1. not-equal (<>),
  2. less than (<),
  3. greater than (>),
  4. less than or equal to (<=),
  5. greater than or equal to (>=),
  6. LIKE,
  7. IN, and
  8. BETWEEN.

7. 1. Introduction 7. 1. 1. <A href="/Tutorial/Oracle/0140__Table-Joins/PerformingSELECTStatementsthatUseMorethanTwoTables.htm">Performing SELECT Statements that Use More than Two Tables</a> 7. 1. 2. <A href="/Tutorial/Oracle/0140__Table-Joins/Threedifferenttypesofjoins.htm">Three different types of joins:</a> 7. 1. 3. Understanding Non-equijoins 7. 1. 4. <A href="/Tutorial/Oracle/0140__Table-Joins/PerformingSELECTStatementsthatUseTwoTables.htm">Performing SELECT Statements that Use Two Tables</a> 7. 1. 5. <A href="/Tutorial/Oracle/0140__Table-Joins/Examplesimplejoin.htm">Example simple join.</a> 7. 1. 6. <A href="/Tutorial/Oracle/0140__Table-Joins/Usetablealiasintablejoin.htm">Use table alias in table join</a> 7. 1. 7. <A href="/Tutorial/Oracle/0140__Table-Joins/ConvertsubqueriestoJOINs.htm">Convert subqueries to JOINs</a> 7. 1. 8. <A href="/Tutorial/Oracle/0140__Table-Joins/autotraceansifullouterjoin.htm">autotrace ansi full outer join</a>

Use table alias in table join

SQL>
SQL> CREATE TABLE employee (
  2  id           number,
  3  name         varchar(100),
  4  birth_date   date,
  5  gender       varchar2(30) );
Table created.
SQL>
SQL> CREATE TABLE employee_evaluation (
  2  id           number,
  3  title        varchar2(100),
  4  written_date date );
Table created.
SQL>
SQL>
SQL> SELECT a.id,
  2         a.name,
  3         p.title,
  4         p.written_date
  5  FROM   employee a,
  6         employee_evaluation p
  7  WHERE  a.id = p.id
  8  ORDER BY a.name,
  9         p.written_date,
 10         p.title;
no rows selected
SQL>
SQL> drop table employee;
Table dropped.
SQL>
SQL> drop table employee_evaluation;
Table dropped.