21.9 SELECT

The SELECT clause is the workhorse of queries and performs the same job as select(), mutate(), rename(), relocate(), and, as you’ll learn in the next section, summarize().

select(), rename(), and relocate() have very direct translations to SELECT as they just affect where a column appears (if at all) along with its name:

planes |> 
  select(tailnum, type, manufacturer, model, year) |>
  show_query()
## <SQL>
## SELECT tailnum, "type", manufacturer, model, "year"
## FROM planes
planes |> 
  select(tailnum, type, manufacturer, model, year) |> rename(year_built = year) |> 
  show_query()
## <SQL>
## SELECT tailnum, "type", manufacturer, model, "year" AS year_built
## FROM planes
planes |> 
  select(tailnum, type, manufacturer, model, year) |>
  relocate(manufacturer, model, .before = type) |> 
  show_query()
## <SQL>
## SELECT tailnum, manufacturer, model, "type", "year"
## FROM planes