project
rel.project([:a, :b, ...])rel.project(['a', 'b', ...])Problem
Section titled “Problem”Keep only some attributes from a relation (this might cause some tuples to become duplicates of others and thus be removed).
Example: What are the different T-shirt variants we stock, if we only consider colors?
Description
Section titled “Description”Creates a new relation with a heading whose attributes is a subset of that of the original.
To understand the name, think of a three-dimensional object casting a shadow on a two-dimensional plane. The shadow preserves some of the object’s shape. It is a projection of the three-dimensional object. In the same way, the project operation reduces the dimensionality of a relation.
Requirements
Section titled “Requirements”The specified attributes must be part of the input relation’s heading.
Examples
Section titled “Examples”Consult the Overview page for the data model used in this example.
suppliers.project([:city]).to_a
=>[ {:city=>"London"}, {:city=>"Paris"}, {:city=>"Athens"}]Generated SQL
Section titled “Generated SQL”SELECT DISTINCT `t1`.`city`FROM `suppliers` AS 't1'suppliers.project(['city']).toArray()
// =>// [// { city: "London" },// { city: "Paris" },// { city: "Athens" }// ]