MySQL: Update table column from subquery result
- by Jhourlad Estrella
On the Members table are columns "MemberID" and "PointsEarned".
I want to update the PointsEarned column from the result of this query:
SELECT m.MemberID, m.UserName,
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=2)*10 ) +
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=3)*3 ) +
( (SELECT COUNT(*) FROM ChatMessages as c WHERE c.MemberID=m.MemberID)*.1 )
as PointsEarned
FROM Members as m
Can anybody tell me how I should do it with a single query?
Thanks!