SQL Tutorial

Joining Techniques

📚 Schema reference · PNW flights 5 tables
airlines
  • carrier
  • name
airports
  • faa
  • name
  • lat
  • lon
  • alt
  • tz
  • dst
  • tzone
flights
  • year
  • month
  • day
  • dep_time
  • sched_dep_time
  • dep_delay
  • arr_time
  • sched_arr_time
  • arr_delay
  • carrier
  • flight
  • tailnum
  • origin
  • dest
  • air_time
  • distance
  • hour
  • minute
  • time_hour
planes
  • tailnum
  • year
  • type
  • manufacturer
  • model
  • engines
  • seats
  • speed
  • engine
weather
  • origin
  • year
  • month
  • day
  • hour
  • temp
  • dewp
  • humid
  • wind_dir
  • wind_speed
  • wind_gust
  • precip
  • pressure
  • visib
  • time_hour

INNER JOIN

  1. Join flights (as f) with weather (as w) on origin and time_hour (returning only the rows matching between both tables). Select the origin, dest, temp, and humid fields.

LEFT JOIN

  1. Left join flights with planes on tailnum (returning all rows from flights and only the rows from planes that match). Select the tailnum, origin, dest, manufacturer, and model fields.

Anti-Join

  1. Anti-join flights (as f) with planes (as p) where plane’s tailnum is missing. Select the tailnum, origin, and dest fields.

Write your own queries!