Oracle self join | self join - oracle tutorial - sql tutorial



What is Oracle self join ?

  • A self join is a join in which a table is joined with itself.
  • To join a table itself means that each row of the table is combined with itself and with every other row of the table.
  • The table appears twice in the FROM clause and is followed by table aliases that qualify column names in the join condition.
  • Oracle self join query

    Oracle self join query

  • The self join can be viewed as a join of two copies of the same table. The table is not actually copied, but SQL performs the command as though it were.
  • To perform a self join, Oracle Database combines and returns rows of the table that satisfy the join condition
 self join

Syntax:

SELECT a.column_name, b.column_name... 
FROM table1 a, table1 b 
WHERE a.common_filed = b.common_field; 
click below button to copy the code. By - oracle tutorial - team

Note: Rename at least one table name temporarily in the sql statement.
WHERE clause could be any given expression based on your requirement.

Sample Database:

  • We have a table called wikitechy_employee with four fields (id, name, position, and city). It contains the following data:
 left outer join in oracle

 joins in dbms

Using select Statement we are selecting name and id from the table.
Again we have selected the name column from the same table using reference from name column

  1. We temporarily created a new table called wikitechy_employee c2 and joining them using join keyword.
  2. C1.Name <> c2.Name to ensure that we don’t get the same customer.

The output returns all the employees from the same city.


This tutorial provides an indepth knowledge on the following items such as oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , mysql tutorial , sql tutorial for beginners , learn sql , oracle database tutorial , sql query tutorial , oracle dba tutorial , plsql tutorial , oracle tutorial pdf , oracle pl sql tutorial , oracle sql tutorial , sql tutorial point , oracle tutorial for beginners , learn oracle online free , learn oracle online , learning pl sql programming , learn sql online for free , sql learning online , dba oracle tutorial , oracle sql tutorial advanced , oracle 11g dba tutorial with examples , oracle online learning , oracle learning online , how to learn pl sql , sql coding tutorial , sql learning websites , sql basic learning

Related Searches to oracle self join | self join