title: How to use value from one table as column name in another table in SQL query
body: <p>Let's say I have two tables:</p>
  <p>Flights looks like:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>flight_num</th>
  <th>dep_apt_code</th>
  <th>arr_apt_code</th>
  <th>date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>34</td>
  <td>ATL</td>
  <td>JFK</td>
  <td>2022-06-01</td>
  </tr>
  <tr>
  <td>48</td>
  <td>IAD</td>
  <td>SFO</td>
  <td>2022-06-02</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>and Weather:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>date</th>
  <th>ATL</th>
  <th>IAD</th>
  <th>JFK</th>
  <th>SFO</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2022-06-01</td>
  <td>cloudy</td>
  <td>windy</td>
  <td>rainy</td>
  <td>sunny</td>
  </tr>
  <tr>
  <td>2022-06-02</td>
  <td>sunny</td>
  <td>rainy</td>
  <td>rainy</td>
  <td>windy</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>where the names of the columns correspond to values in two of the columns in the Flights table.</p>
  <p>Currently, I want to reference the column corresponding to Flights.dep_apt_code in Weather to create a table like:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">date</th>
  <th style="text-align: center;">flight_num</th>
  <th style="text-align: right;">dep</th>
  <th>arr</th>
  <th>weather</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">2022-06-01</td>
  <td style="text-align: center;">34</td>
  <td style="text-align: right;">ATL</td>
  <td>JFK</td>
  <td>cloudy</td>
  </tr>
  <tr>
  <td style="text-align: left;">2022-06-02</td>
  <td style="text-align: center;">48</td>
  <td style="text-align: right;">IAD</td>
  <td>SFO</td>
  <td>rainy</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>but I haven't been able to figure it out. I'm not the biggest expert on advanced queries, so even if someone can just point me to resources that may help me figure this out, it would be greatly appreciated.</p>
  <p>I tried something like:</p>
  <pre><code>SELECT
      F.date,
      F.flight_num,
      F.dep_apt_code as dep,
      F.arr_apt_code as arr,
      W.F.dep as weather
  FROM Flights as F JOIN Weather as W
  WHERE F.date = W.date;
  </code></pre>
  <p>but obviously that doesn't work, I just don't know syntactically how to do it.</p>
  <p>How does one reference a column using a value from another table?</p>