How to specify the parent query field from within a subquery in mySQL?

前端 未结 6 1009
心在旅途
心在旅途 2020-12-03 02:24

Is there a way to specify the parent query field from within a subquery in mySQL?

For Example:
I have written a basic Bulletin Board type progra

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 02:51

    Parent query field within a subquery in MySQL 8.

    I'm selecing games scores on the basis of username from tblgamescores using nested query.

    SELECT 
        GameScoresID, 
        (SELECT Username FROM tblaccounts WHERE AccountID = FromAccountID) AS FromUsername, 
        (SELECT Username FROM tblaccounts WHERE AccountID = ToAccountID) AS ToUsername,
        (SELECT Username FROM tblaccounts WHERE AccountID = WinAccountID) AS WinUsername,
        (SELECT Username FROM tblaccounts WHERE AccountID = LossAccountID) AS LossUsername,
        FromUserScore,
        ToUserScore 
    FROM tblgamescores a 
    WHERE FromAccountID = (SELECT AccountID FROM tblaccounts WHERE Username = "MHamzaRajput");
    

提交回复
热议问题