C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Query


Posted Date: 31 Oct 2009      Posted By: janardhanReddy      Member Level: Silver     Points: 1   Responses: 6



hi all,
I have one table which have empid,ename,Mid. Mid id foreignkey where empid is primarykey so i want to display employeename and managername.





Responses

Author: Manvinder Kaur     31 Oct 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

I did not get your question...


Author: ABitSmart    31 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

I think you want this,

select t2.EmployeeName, t3.ManagerName from table1 t1
inner join table2 t2 on t2.id = t1.empid
inner join table3 on t3.id = t1.Mid

where,
table1 is the table with empid,ename,Mid
table2 has employee information id,EmployeeName
table3 has manager information id, name



Author: Manvinder Kaur     31 Oct 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

do not duplicate employee name in two tables....t1 ename and t2 EmployeeName


Author: Manick    01 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

select a.empname, b.mgrname from current_table a inner join foreign_table b on b.empid = a.mid

Regards,
Manick



Author: Sridhar    01 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

select e1.empname,e2.empname from tablename e1, tablename e2 where
e1.mgrid = e2.empid



Author: Christopher    02 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

you have to use Self join for this query

query is

select a.empid,a.empname as Managername from employeedetails a join employeedetails b on a.managerid=b.empid



Post Reply
You must Sign In to post a response.
Next : How to dump or store entire datatable in a database table
Previous : Sql Server performance
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use