|
|
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](https://www.postgresql.org/docs/9.5/static/sql-select.html#SQL-DISTINCT)
|
|
|
|
|
|
## How it works
|
|
|
```ruby
|
|
|
distinct_on(*columns)
|
|
|
```
|
|
|
|
|
|
```ruby
|
|
|
# SELECT DISTINCT ON ( "users"."name" ) "users".* FROM "users"
|
|
|
User.distinct_on(:name).all
|
|
|
```
|
|
|
|
|
|
You can use where-like syntax to find more complex columns:
|
|
|
```ruby
|
|
|
# SELECT DISTINCT ON ( "users"."name" ) "users".* FROM "users"
|
|
|
User.distinct_on(:name).all
|
|
|
``` |
|
|
\ No newline at end of file |