Search code examples
mysqlsqlexecution

SQL query more time to execute and finally get error


UPDATE member
SET member.usableSum = (SELECT usablesum
        FROM fundrecord
        WHERE (member.id= fundrecord.memberId) AND id IN (
        SELECT MAX(id)
        FROM [enter image description here][1]fundrecord
        GROUP BY memberId)
        )

Solution

  • I am guessing that you want:

    UPDATE member m
        SET m.usableSum = (SELECT fr.usablesum
                           FROM fundrecord fr
                           WHERE m.id = fr.memberId
                           ORDER BY fr.id DESC
                           LIMIT 1
                          );
    

    This returns the "most recent" usablesum from fundrecord for each member.