I have a question more to serve my curiosity/understanding. I have a MySQL statement that does some calculations on the fly, and I am using the coalesce function to return a 0 if there are no records.
Everything works, however I want to sort it in Descending order and only show the top 10. This kind of works, but it doesnt interpret my data right.
For example, lets say I have these values:
It will sort it in a fashion where it thinks 9 is the highest number, 8 is the second highest, and so on. It seems to only look at the first number of a double digit number. The column data type is INT(11).
Here is my command:
If I remove the COALESCE it works fine, but I like having it there incase there are nulls.
, coalesce(sum(s.goals),'0') as goals
, coalesce(sum(s.assists),'0') as assists
, coalesce(sum(s.fouls),'0') as fouls
, coalesce(sum(s.assists + s.goals),'0') as points
FROM league as p
LEFT OUTER JOIN (SELECT goals
FROM stats) as s
on s.player_id = p.id
LEFT OUTER JOIN (SELECT id
FROM teams) as t
on t.id = p.team
ORDER BY points DESC
If anyone can help it would be appreciated.