What is a self join? Explain it with an example?

Answer Posted / anuj barthwal

A self join applies on one table only

Example:

emp_id emp_name emp_manager_id

1 Anuj NULL

2 Sunny 1

3 Suraj 1

4 Narban 2


if we want to get the name of the managers

select e1.emp_name 'manager',e2.emp_name 'employee'
from employees e1 join employees e2
on e1.emp_id=e2.emp_manager_id

manager employee

Anuj Sunny

Anuj Suraj

Sunny Narban


Self join means joining the single table to itself

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I detect whether a given connection is blocked?

585


How long can an error message be in raiseerror function?

553


When installing the datastage7.5x2 edtion iam getting aproblem i.e the cpu count is 2 but the cpu count in installation is one . how can i install in my p.c (system is dual core).

1789


How to customize error conditions.

1706


What is dbms and its application?

558






You are testing the performance of a query the first time you run the query, the performance is slow. the second time you run the query, the performance is fast. why is this?

527


Explain about relational database management systems?

572


Explain about post-relational databases?

585


Explain the role of indexing in databases?

645


If a column is an image value type, how you can compare column values? How can you use this column in join clause?

597


How you can make a parameterized view?

561


Explain about the hierarchical model of the database?

584


Explain the process of the user request and data generating?

658


What is database design and development?

606


Explain about the database management systems.

570