title: mysql multiple group by
body: <p>Good time! Tell me how to optimize this query and, if possible, unite it into one!</p>
  
  <pre><code>$query  = "SELECT external_source_id FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY external_source_id ORDER BY external_source_id ASC;";
  $query .= "SELECT sources_id FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY sources_id ORDER BY sources_id ASC;";
  $query .= "SELECT ip_country FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY ip_country ORDER BY ip_country ASC;";
  $query .= "SELECT cidr FROM smf_tds_unique_statistic WHERE ".$dateRange." GROUP BY cidr ORDER BY cidr ASC;";
  
  if (mysqli_multi_query($db, $query)) {
  do {
      if ($result = mysqli_store_result($db)) {
  
          while ($row = mysqli_fetch_row($result)) {
              $val = $row[0];
              if ($val != '') {
                  $options .= '&lt;li class="select_input_option_item" value="'.$val.'"&gt;'.$val.'&lt;/li&gt;';
              }
          }
          array_push($optionsArr, $options);
          $options = '';
  
          mysqli_free_result($result);
      }
  
      if (!mysqli_more_results($db)) break;
  } while (mysqli_next_result($db));} mysqli_close($db);
  </code></pre>