|
This sounds like another homework question. However,
it is also probably the most common example of a self-join
ever devised. Everybody uses this example, and it's real easy
to find on the Web, so there's no reason why TechTarget
shouldn't also publish it.
select e.empname
, m.empname as managername
from emp as e
left outer
join emp as m
on m.empid = e.managerid
Whenever you join a table to itself, use table aliases to
distinguish the "copies" of the table. (The optimizer might not actually use
two "copies" of the table, but it is convenient to
think of it as working that way.)
|