21.11 Joins

If we’re familiar with dplyr’s joins, SQL joins are very similar. Here’s a simple example:

flights |> 
  left_join(planes |> rename(year_built = year), by = "tailnum") |> 
  show_query()
## <SQL>
## SELECT
##   flights.*,
##   planes."year" AS year_built,
##   "type",
##   manufacturer,
##   model,
##   engines,
##   seats,
##   speed,
##   engine
## FROM flights
## LEFT JOIN planes
##   ON (flights.tailnum = planes.tailnum)