sql query
-
Saturday, November 17, 2012 6:41 PM
Hello everyone
Recently i faced a question in an interview. Can any one help me in the below scenario.
There is a table with four columns. Developer, Team Lead, Project Lead, Manager.
I need to get an output like this
Developer should be working under Team lead and
Team lead should be working under Project Lead and
Project Lead should be working under Manager.
Can any one help plz
Thanks
kumar
All Replies
-
Saturday, November 17, 2012 6:53 PM
Hi
Check the below Queries
SELECT d.Developer,t.TeamLead FROM TableName d,TableName t where d.Developer=t.TeamLead SELECT t.TeamLead,P.ProjectLead FROM TableName t,TableName P where t.TeamLead=P.ProjectLead SELECT P.ProjectLead,M.Manager FROM TableName P,TableName M where P.ProjectLead=M.Manager
PS.Shakeer Hussain
-
Saturday, November 17, 2012 6:55 PMModerator
There is a table with four columns. Developer, Team Lead, Project Lead, Manager.
Your interview answer should be: that is the wrong design. Employee hierarchies should be implemented like the Employee table (ManagerID self-referencing FOREIGN KEY column) in AdventureWorks:
http://www.sqlusa.com/bestpractices2005/organizationtree/
Kalman Toth SQL 2008 GRAND SLAM
New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012
- Edited by Kalman TothMicrosoft Community Contributor, Moderator Saturday, November 17, 2012 7:51 PM
- Proposed As Answer by Naomi NMicrosoft Community Contributor, Moderator Sunday, November 18, 2012 3:47 AM
-
Sunday, November 18, 2012 5:21 AM
Hi,
Without making an hireachical table with parent child relationship you can't do .So hope your question is clear .
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

