title: mysql select from multiple tables where two items match
body: <p>What would be the best way to select data from one table and match it to the data in another then return those both together?</p>
  
  <p>I have a table with a bunch of info in it and it's relevant country name.
  I need to get from another table the country code that matches the name of the country</p>
  
  <p>Would it be best to use say a mysql JOIN function to link the data together or use something like a foreach() to make separate requests to get each item.</p>
  
  <p>I have a feeling JOIN (or something similar) would be the best solution, however I don't really know how to construct the mySQL query bearing in mind I need data returned from both table.</p>
  
  <pre><code>$sql = "SELECT DISTINCT r.country,c.* FROM resorts LEFT JOIN ( SELECT * FROM Country WHERE r.country = c.countryName )";
  </code></pre>
  
  <p>Table 1</p>
  
  <ul>
  <li>country</li>
  </ul>
  
  <p>Table 2</p>
  
  <ul>
  <li>id</li>
  <li>countryName</li>
  <li>countryCode</li>
  </ul>