select query for tables in relation twice.. RRS feed

  • Question

  • User1892459355 posted


    i have a tblmsges, it has foreign keys senderID and RecieverID, both are foreign keys from tblUser..

    now i wana aply a join query which gives me sender and reciever name,, both at a time..... how can i do it???

    Saturday, April 28, 2012 12:41 AM


  • User-1199946673 posted
    SELECT      Sender.Name
    FROM       (tblmsges
    INNER JOIN  tblUser AS Sender   ON Sender.UserID   = tblmsges.SenderID
    INNER JOIN  tblUser AS Reciever ON Reciever.UserID = tblmsges.RecieverID

    Instead of joins, you can use subquerys as well

    SELECT      (SELECT Name FROM tblUser WHERE UserID = SenderID)   AS Sender
               ,(SELECT Name FROM tblUser WHERE UserID = RecieverID) AS Reciever
    FROM        tblmsges

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 28, 2012 3:25 AM