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

Answer Posted / sushant more (sybase dba)

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 ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about post-relational databases?

574


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

579


How to use timestamp datatypes

1568


Explain the rollup operator?

600


Explain about the database management systems.

560






State the acid rules?

672


Which four data types cannot be used as a return type from a user-defined function?

573


Explain the process of the user request and data generating?

644


On friday, you issued several insert statements using query analyzer. You then verified the data had been correctly entered with a select statement on monday, your users report that the data is not there what happened?

548


1. Using the XML Document below, with the URI “recipe.xml” define the following queries in XQuery: a.) Give the names of all breakfast in the menu. b.) Select breakfasts that have price lower than $7.00? Belgian Waffles $5.95 two of our famous Belgian Waffles with plenty of real maple syrup 650 Strawberry Belgian Waffles $7.95 light Belgian waffles covered with strawberries and whipped cream 900 Berry-Berry Belgian Waffles $8.95 light Belgian waffles covered with an assortment of fresh berries and whipped cream 900 French Toast $4.50 thick slices made from our homemade sourdough bread 600 Homestyle Breakfast $6.95 two eggs, bacon or sausage, toast, and our ever-popular hash browns 950

1650


Explain about the storage and physical database design?

521


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

2406


What is dbms explain in brief?

552


How to generate OIDS

1655


Can an extended stored procedure be called from inside a user-defined function?

601