Genadinik
Genadinik

Reputation: 18639

Best way to query for items with the most "upvotes"

I am working on adding up and down votes to some items in the database, and displaying them ordered by the highest upvotes. How would this query look like?

How can I make something like this in SQL?

SELECT col1 col2 FROM some_table WHERE "highest number of upvotes" 

Upvotes: 2

Views: 144

Answers (1)

Mark Byers
Mark Byers

Reputation: 838076

Assuming upvotes is a field in your table, you can use ORDER BY and optionally a LIMIT:

SELECT col1, col2
FROM some_table
ORDER BY upvotes DESC
LIMIT 10

Upvotes: 3

Related Questions