Today I Learned

hashrocket A Hashrocket project

Distinct Query Expression in Ecto

In an Ecto query expression, use distinct: true to ensure the values returned from your query are distinct.

from(u in User, distinct: true, select: u.first_name)

You can also use distinct with an expression to be more specific

from(u in User, 
  distinct: last_name,
  order_by: [asc: :last_name])
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.