Help with Query-one primary key in a table linked to many column in the second table as a forein key

  • 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

  • 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.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • 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

  • 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