what is self join in sql

/* SELF JOIN - Joining a table with itself is called as self join.
  It is classified under any type of join.
  INNER JOIN
  OUTER JOIN
CROSS JOIN. */
SELECT Column_List
FROM Left_Table_Name AS Alias_Name
JOIN_TYPE Right_Table_Name AS Alias_Name
ON Alias_Name.Column_List [Operator] Alias_Name.Column_List

/* Example*/
SELECT E.Name AS Employee, M.Name AS Manager
FROM tblEmployee E
LEFT JOIN tblEmployee M
ON E.ManagerID = M.EmployeeID

5
1
Awgiedawgie 440215 points

                                    Self is joining a table to itself.

-- assume employee table as 2 different table using different alias 
-- as  manager and worker 
-- we want to join these 2 virtual manager and worker table 
-- to get manager's first name and worker's first name 
-- our condition is worker's manager_id match managers employee id

SELECT  manager.FIRST_NAME AS MANAGER_NAME , 
        worker.FIRST_NAME AS WORKER_NAME 
FROM EMPLOYEES manager 
INNER JOIN EMPLOYEES worker on worker.MANAGER_ID = manager.EMPLOYEE_ID  

order by 1 
;

5 (1 Votes)
0
4
10
Awgiedawgie 440215 points

                                    SELECT
    e.first_name + ' ' + e.last_name employee,
    m.first_name + ' ' + m.last_name manager
FROM
    sales.staffs e
INNER JOIN sales.staffs m ON m.staff_id = e.manager_id
ORDER BY
    manager;

4 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
why we use self join in sql how to perform self join in sql why do we need self join sql Self joins. when to self join sql why do we need self join in sql self join select query SELF OUTER JOIN self -join how to self join in sql 2) What is a self-join and how is it used? how to create self join why do we use self join in sql sql why use self join when do we use self join in sql when we use self join in sql how self join works in sql self.join why should i self join sql when is self join used in sql when to use self join sql self join querry what's the self join self join querry syntax when we can use self join selfe join sql sql self join example sql server what is self join used for… example? sql self join tutorial self left join in sql self join in sql sql self joins sql sql self join <> self join use purpose of self join in sql Why SQL Self Join? when to use a self join use of self join when do we do self join in sql why self join is used where is self join used What is a self join? Explain it with an example. <> in self join self join query join self self join in sql oracle what are joins and self join in sql what does self join self join in sql waht it does when in self join used? SQL SELF JOINM' why do we do self join in sql what is self join used for self-join.sql when to use self joins sql selfjoin self join sql exsample self in joins sql how to make self join in sql sql server self join sql self join explained Do you need to use ON for self Join in sql sql self joins when use self join where we use self join in sql how to write self join in sql self join in sq self join\ self join table sql self join example in sql server query self join sql self-join 1:1 sql self-join 1:1 example self-join 1:1 example self join query in sql server self join queries in sql self joins operator in sql how to use self join in sql self join keyword in sql sql self join result how to self join table in sql join same table sql sql join within same table sql join table to same table how to join a table with itself join a table from sql query with itself join query with itself sql join table to self self join in ms sql server join the same table sql sql join to same table join table to itself sql self join my sql example sql auto join Auto / Self Joins self join syntax how to join a table to itself in sql table self join self table query what is a self join sql self join in sql server with example table join on itself join table on its self self hoin mysql aelf join sql how to join a table with itself sql sql join table to itself self join sel self inner join in sql with indexes and explain function what is the self join sql query self join example mysql self inner join php mysql self join how self join works in sql with html select example how self join works in sql with example join on the same table sql self joun query to join table to itself sql what is self join with example self jion sql server self join example self join in dbms self join examle self referencing sql query sql self joins explained sql self joins with examples join table with itself sql Self joins self table reference in sql mysql self join min selj join in sql self join in sql with example example of a SELF JOIN? self join table self join example in mysql sql self join queries how to self join php mysql sql from same tables autojoin function mysql select self join self join a table sql Which of the query in SQL is an example of self-join? I. SELECT a.column_name FROM table1 a, table1 b WHERE a.x = b.x; II. SELECT b.column_name FROM table1 a, table2 b WHERE a.y = b.y; self join sql examples self join w3schools self joins in dbms how to use self join in mysql sql server self join syntax explain self join with example self referential sql self join query in sql sql query on same table self outer join in sql self join sql example sql join query to itself self join code how to apply selef join mysql self join self join mysql self-joins sql sql join same table what is self join wpractical applications of self join in sql when to use self join in sql mysql selfjoin self join practical example sql self join hierarchical data self join in mysql self join sql query self join examples sql self join examples what is self join in sql self inner join in sql example of self join self join sql what is the use of self join in sql create table with self join in sql sql self join example self join what is it example use of self join in sql sql self join self join in sql server self join sql with example self join self join in sql self join sql server self join example
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source