title: SQL query to get all rows that have data linked by a FK in another table
body: <p>I have three tables: <code>Station</code>, <code>MonthlyNormalData</code> and <code>SubArea</code>. I'm trying to get all stations in a sub area that have at least one monthly data tied to it. With the following query, I am able to get all stations in a sub area, but this is disregarding the part about monthly data ($region is a variable containing the region name in my PHP script):</p>
  
  <pre><code>SELECT S.station_id, S.name, SA.sub_area_name
  FROM dev.Station AS S
  INNER JOIN dbo.SubArea AS SA ON S.sub_area_id = SA.sub_area_id
  WHERE sub_area_name = '$region'
  </code></pre>
  
  <p>I have also tried the following query, but it returns one row for each monthly data associated with a station, which is not really what I am looking for (only looking for something that sends me the names of the stations that have at least one monthly data associated to it, not all rows containing that data):</p>
  
  <pre><code>SELECT S.station_id, S.name, SA.sub_area_name
  FROM dev.Station AS S
  INNER JOIN dbo.SubArea AS SA ON S.sub_area_id = SA.sub_area_id
  INNER JOIN data.MonthlyNormalData as MND ON MND.station_id = S.station_id 
  WHERE sub_area_name = '$region' AND MND.value IS NOT NULL
  </code></pre>
  
  <p>What would be the query I would need to run to only have one row per station that have a monthly data associated with it within a certain sub area?</p>