Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering mysql rows from derived columns

I wanted to retrieve rows from the mysql database and order them by votes:

votes_up + votes_down = votes

table:

posts{id, post_text, votes_up, votes_down, date}
ORDER BY votes
like image 564
getaway Avatar asked Sep 05 '26 05:09

getaway


1 Answers

SELECT id, post_text, votes_up, votes_down, date, sum(votes_up + votes_down) as 'Votes'
FROM posts
ORDER BY sum(votes_up + votes_down)
like image 86
Bryan Denny Avatar answered Sep 06 '26 19:09

Bryan Denny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!