I have a script to count a users points in a simple achievements type script, then display them on a web page in order. I have the following mySQL function, but if a user doesn’t have any points as yet (i.e there is no ‘pa.userid’ to be found, then the user does not get fetched at all)
SELECT u.userid,
SUM(IF(pa.plus = '1', pa.points_amount, 0)) - SUM(IF(pa.plus = '0', pa.points_amount, 0)) AS points
FROM awarded_points pa,
users u WHERE u.userid = pa.userid
GROUP BY u.userid
ORDER BY points DESC
LIMIT 10
How would i go about making the above code include users that haven’t yet got any points? Is it a complicated change?
Use a
left outer joinSee that great explanation of joins