본문 바로가기
SQL

[LeetCode] Employees Earning More Than Their Managers (Self Join)

by YGSEO 2021. 4. 8.
728x90
select e.Name as Employee 
from Employee as e join Employee as m on m.Id = e.ManagerId
where e.Salary > m.Salary

위 코드에서 e는 Joe, Henry 만 남아있고(join의 결과 managerID == ID)

m은 Sam, Max만 존재하는 것이다.

 

self join

www.w3schools.com/sql/sql_join_self.asp

 

SQL Self Join

SQL Self Join SQL Self Join A self join is a regular join, but the table is joined with itself. Self Join Syntax SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition; T1 and T2 are different table aliases for the same table. Demo Database In thi

www.w3schools.com

 

728x90

댓글