Combine Results with union and union_all Options

Learn how to combine results of different queries using union and union_all.

The union option

To combine the results of different queries, SQL provides the UNION operator. We can perform union queries in Ecto by adding the union: option to our queries. The two queries need to have result sets with the same column names and data type for this to work.

Here’s how we can use union: to get the titles of all our albums and tracks.

Get hands-on with 1200+ tech skills courses.