I know questions like this have been asked before, but I’m not sure how I can apply it to my code. I have two tables. I have an entry table that stores entries like this:
id | name | description
1 Test Test entry
In the other table, I have a rating table like this:
id | entryid | rating
1 | 1 | 1
2 | 1 | -1
I want to list all the entries in the first table, but order them by the total rating. So, in this example, Entry #1 would have a rating of 0, because 1 + -1 = 0. Is there a way that I can do this with a query?
Check this SQLFIDDLE DEMO. You just need to use
Sumto count all ratings per eachentryID.Query:
Result:
Final Query:
Final Results: