order by an average in another table (basically a "top 10" list)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've done a google search, but most of the results are for the part I've already figured out. People that have the "top 10" sorting usually want money for their system (one wanted an absurd $500).

I'm working on a database application where users vote on how much they like a particular picture. All of the picture information is in one table, and all of the votes are within another table. The picture table's auto incrementing id is referenced in the ratings table.

Displaying the actual average rating of a particular photograph is easy enough:
"SELECT avg(rating) FROM ratings WHERE parent_id = '$id'"


But how the heck would one select the top $n entries, ordered by the average of the photo's ratings? Ideally, I'd like the query to work in both MySQL and PostgreSQL.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux