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

Answer Posted / sanchit aggarwal(oracle dev.)

CREATE TABLE EMPLOYEE(

[EMPLOYEE_ID] INT PRIMARY KEY,

[NAME] NVARCHAR(50),

[MANAGER_ID] INT

)

GO

INSERT INTO EMPLOYEE VALUES(101,'Mary',102)

INSERT INTO EMPLOYEE VALUES(102,'Ravi',NULL)

INSERT INTO EMPLOYEE VALUES(103,'Raj',102)

INSERT INTO EMPLOYEE VALUES(104,'Pete',103)

INSERT INTO EMPLOYEE VALUES(105,'Prasad',103)

INSERT INTO EMPLOYEE VALUES(106,'Ben',103)


select e1.name from employee e1,employee e2
where e1.employee_id = e2.manager_id

Is This Answer Correct ?    31 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the rollup operator?

585


What you can do to remove data from the cache and query plans from memory for testing the performance of a query repeatedly?

569


What is a database development?

501


What is normalization? Explain different levels of normalization?

59653


Hi my program is accesing data from two db2 databases.what is the bind card for this program to genarate plan? how to specify the two owners and two qualifiers in bind card

1656






What is data modeling with example?

512


I HAVE A PI ON COL A THE NEXT DAY I WANT CHANGE THE PI ON COL B? PLS SEND ME THE ANS

2393


Which data type cannot be used as a parameter in a udf?

552


Why does this query return 0?

603


What is dbms explain in brief?

539


In which database can extended stored procedures be added?

508


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

565


How to generate OIDS

1635


What are the main phases of database development?

514


Write the fastest query to find out how many rows exist in a table?

637