问题
There is one model named Book, I want to get all books, but all results have distinct column named 'author', how to do this ? thanks!
回答1:
May be by:
Book.select("DISTINCT(author)")
for more read this: Active Record Query Interface
Edit
You can try: find_by_sql
as
Book.find_by_sql("select * from books group by author")
来源:https://stackoverflow.com/questions/5701911/how-to-select-record-by-distinct-column-in-rails3