March 23, 2010 at 2:27 am
I have two tables( Eg EMPLOYEE and TRANSACTION).
EMPLOYEE table has columns ( EmpID,EmpFirstname,EmpLastName) with EmpId as a primary key.
TRANSACTION table has columns(TansID,RegisteredBYEmpID,ApprovedByEmpID,RigistrationDate,ApprovedDate.....) ,here TransId is the primary key and both RegisteredBYEmpID and ApprovedByEmpID are foreinKey from EMPLOYEE table both refering to the same Column (EmpID).
Now both RegisteredByEmpID and ApprovedByEmpID store numbers in Transaction Table and I want to retrieve the details of employees who registered and Aproved a single transaction. Could you help me ......
Thank you for your time and consideration
March 23, 2010 at 2:53 am
SELECTE.*
FROMTRANSACTION T
INNER JOIN EMPLOYEE E ON T.RegisteredBYEmpID = E.EmpID
WHERET.RegisteredBYEmpID = T.ApprovedByEmpID
I hope this will give you the desired result. It would have been better if you had provided some sample data as well.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 23, 2010 at 3:01 am
Select
EmpID
, EmpFirstname
, EmpLastName
From EMPLOYEE E inner join TRANSACTION T
On
E. EmpID = T. RegisteredBYEmpID
Where T. RegisteredBYEmpID= T. ApprovedByEmpID
I guess this should work. please try and let me know
March 24, 2010 at 9:12 am
Realy thank you very much for your reply.
My problem is solved by other forum as follows. It is 100% correct
select registredBy.EmpFirstname,
registredBy.EmpLastName,
approvedBy.EmpFirstname,
approvedBy.EmpLastName, ...
from transactions
join employee as registredBy
on transactions.RegisteredBYEmpID = registredBy.EmpID
join employee as approvedBy
on transactions.approvedBYEmpID = apporovedBy.EmpID
it may be help full for othrs who want help like me in this............
Thank you alll for your help
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply