Help Forming An SQL Query That Selects The Max Difference Of Two Fields

Posted by Frank on Stack Overflow See other posts from Stack Overflow or by Frank
Published on 2010-03-12T03:13:41Z Indexed on 2010/03/12 3:17 UTC
Read the original article Hit count: 251

Filed under:
|

I'm trying to select a record with the most effective votes. Each record has an id, the number of upvotes (int) and the number of downvotes (int) in a MySQL database.

I know basic update, select, insert queries but I'm unsure of how to form a query that looks something like:

SELECT * FROM topics WHERE  MAX(topic.upvotes - topic.downvotes).

Please excuse my made up SQL. The tutorials on SQL I find on the internet cover very basic stuff. Does anyone recommend a good book on this subject?

© Stack Overflow or respective owner

Related posts about sql

Related posts about query