sql help...getting user with the most recipes from table?

I assume a user has_many howtos and a howto belongs_to a user in the respective models

@temp = User.find(:all, :select => “users.id,users.username, count( howtos.id) as numhowtos”, :joins => “left join howtos on users.id = howtos.user_id”, :order => “numhowtows DESC”)

Adam

@temp = Howto.find_by_sql (["select user_id from Howtos Order by

user_id.count limit 10" ])....

Here is a description of how to use MySQL count() function. http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html

You probably want to do something like:

select count(user_id), user_id from Howtos group by user_id

This is an aggregate query, so you'd use GROUP rather than ORDER. hth