I am having problem sorting joined mysql results, having two related tables:
Table users:
id, name
--------
1, Alex
2, John
Table votes:
user_id, vote
-------------
1, 1
1, 1
1, 1
1, -1
1, -1
2, 1
2, 1
2, 1
Alex have 1 vote score in summary
John have 3.
Therefore John will be first, Alex second.
How can i get users list ordered by sum of “vote” field on votes table ?
“vote” field are integer (can be 1,-1,0 or any other integer).
You could use this MySql query that uses GROUP BY, and aggregated function SUM:
see it here.