Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

Oracle: Self Join

Profile picture for user akshita.goel
Written by akshita.goel on 11/09/2021 - 14:18

To understand SELF JOIN in Oracle you all need to understand How basic join works. SELF JOIN in oracle is used to perform join with a similar table. Although, Joining Tables always happen between two different tables, However here in self join we join a table with itself with help of an alias. This relation of the table with itself is described by the word Unary Relationship. 

Syntax

Select Column from Table alias1, Table alias2
where condition...

Let's not confuse ourselves and understand the concept step by step:

Suppose we have the following Marks_Stu Table:

Self Join

Step 1: Firstly lets consider 1st part of the code i.e :

Select * from Marks_Stu from Marks_Stu a, Marks_Stu b;
  1. Marks_Stu is the name of the Table.
  2. As, we all know that Joins are always applied between two tables. But here as per the functioning of SELF JOIN the same table is join with itself. Therefore, to fulfil the criteria of Self Join we use different alias a & b. In easy terms you can understand the concept by considering that two copy of Table Marks_Stu is generated. One is named as a and other is named as b.
  3. The Output of step 1 will just provide the cartesian product of table a with table b, in short with itself.

Output

self join

Step 2: Now, Where condition; part of syntax will filter the data according to the condition applied and will output the specific result:

WHERE a.Marks = b.Marks;

The above code specifies that we need those records which have same Marks entries in Cartesian Product above.

Now, if we join Step1 and Step2, we can make a code as:

select * from Marks_Stu a, Marks_Stu b
WHERE a.Marks = b.Marks;

Output

self join

Related Content
Oracle Tutorial
Oracle: Left Outer Join Or Left Join
Oracle: Right Outer Join Or Right Join
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use