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
How can you fix a poorly performing query?
Why does this query return 0?
You have a table with three columns: amount1, amount2, and amount3 in a single row only one of these three columns will have a value and the other two will be null. Write a sql query to retrieve the values from these columns?
How to combine two function together?
If a column is an image value type, how you can compare column values? How can you use this column in join clause?
How would you design a database for an online site, which would average a million hits a day?
How to customize error conditions.
fact table and dimension table containg one to many relationship or many to one relastionship
There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better?
What is database design and development?
What you can do to remove data from the cache and query plans from memory for testing the performance of a query repeatedly?
To convert IDMS to DB2, how to deal with IDMS occurs and redefined clause?
How long can an error message be in raiseerror function?
Explain about the relational database?
Explain the role of indexing in databases?