Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle SELF JOIN

In Oracle, SELF JOIN is used to combine rows with other rows in the same table. In other words table is joined with itself. This can be achive with the help of table alias to distinguish the left table from the right table of the same table in a single query.

Oracle SELF JOIN Syntax

To combine rows with other rows in the same table, use the following syntax:

Syntax

SELECT col1, col2,....
FROM tablename1 A, tablename1 B
WHERE condition;

Parameters:

tablename1: The table name from which you want to fetch records.

col1: The column or field name that will be return.

Oracle SELF JOIN example

The following Oracle, combining rows with other rows in the same table using SELF JOIN:

Example

SELECT A.firstName, A.lastName, B.firstName, B.lastName
FROM tblCustomerLoan A, tblCustomer B
WHERE A.firstName <> B.firstName;

Note:

In the above example, we are combining rows with other rows in the same table using SELF JOIN.