MySQL-like group by statement on queries. It keeps only the first row of each set of rows where the given expressions evaluate to equal. PostgreSQL Docs
How it works
distinct_on(*columns)
# SELECT DISTINCT ON ( "users"."name" ) "users".* FROM "users"
User.distinct_on(:name).all
You can use where-like syntax to find more complex columns:
# SELECT DISTINCT ON ( "users"."name" ) "users".* FROM "users"
User.distinct_on(:name).all