Mysql select distinct ID and name
<p>I have a MySQL table with some fields. There's a problem with 2 fields.</p>

<p>Fields are <code>official_country_name_sort_field</code> that contain unique numbers and field "official_country_name" that contain names.</p>

<p>I want to select <code>official_country_name_sort_field</code> that is unique and use it in GET method, but on site I want to show names from <code>official_country_name</code>.</p>

<p>I have this function that show id's from <code>official_country_name_sort_field</code>:</p>

<pre><code>$sql = "select distinct official_country_name_sort_field as name from t_container,t_country where  (t_container.country_id = t_country.id) and (t_container.category = '$category') and (t_country.slug = '$slug') order by t_container.official_country_name_sort_field";

   $result = mysqli_query($link,$sql);
   if (!$result) {
         $output = 'Error fetching official country names : '.mysqli_error($link);
         include   '../templates/db/error.html.php';
         exit();
    }
    $officialCountryNames = array();
    while ($row= mysqli_fetch_array($result)) {
         $officialCountryNames []  = $row['name'];

    }

    return $officialCountryNames;

}
</code></pre>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php foreach ($officialCountryNames as $officialCountryName ) : ?&gt;
      &lt;h3&gt;  &lt;a href="&lt;?php echo "../currencylist?showall&amp;country=$slug&amp;category=$category&amp;official_name=$officialCountryName"; ?&gt;  "&gt;&lt;?php  echo "$officialCountryName"; ?&gt;&lt;/a&gt;&lt;/h3&gt;
      

      &lt;?php endforeach  ?&gt;</code></pre>
</div>
</div>
</p>

<p>This show, where I have "officialCountryName" - ID's (numbers from table column "official_country_name_sort_field". How can I show names from table column "official_country_name" instead of ID's from "official_country_name_sort_field".</p>