Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi Experts,
Sql Table was like this,

Ex: EmployeeTable (EmpId, EmpName, CreatedEmpId, updatedEmpId)

now my question is how to get EmpName,CreatedEmpName,UpdatedEmpName

thanks in advance

Regards
Sandeep Chowdary
Posted
Updated 8-Feb-13 1:56am
v3
Comments
Hemant Singh Rautela 8-Feb-13 8:13am    
A uncleared question, uncleared ans,

I think you are playing for increasing your score.... BOTH..

where are your column CreatedEmpName,UpdatedEmpName..??
if you want to select query , then why not use select * from EmployeeTable.. very simple

:-)

1 solution

Assuming that CreatedEmpId and updatedEmpId relate back to the EmployeeTable you can do this:

SQL
SELECT EmpName, a.EmpName as CreatedEmpName, b.EmpName as UpdatedEmpName
FROM EmployeeTable e 
LEFT JOIN EmployeeTable a ON e.CreatedEmpID = a.EmpID
LEFT JOIN EmployeeTable b ON e.updatedEmpId = b.EmpID


Essentially, you just join back to the same table twice to get the other names.
 
Share this answer
 
Comments
sandeep nagabhairava 8-Feb-13 8:06am    
thanks ryanb... My 5!
ZurdoDev 8-Feb-13 8:12am    
Sure. Glad to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900