title: Group by is not showing all the rows
body: <p>I am working in WordPress and below is my select query. I have used leftjoin and group by. But only one row is returned if I have duplicate entries in my articles.username coloumn. So I want all the rows to be returned with group by and duplicates should be allowed in username field.
  PHP Code</p>
  
  <pre><code>$sqll = "SELECT articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title, Sum(zvotes.zvotes) AS votessum FROM articles LEFT JOIN zvotes on articles.aid=zvotes.aid GROUP BY articles.competition HAVING articles.category = '$cat' &amp;&amp; articles.competition = '$comp' ORDER BY votessum";
  
      $results = $wpdb-&gt;get_results($wpdb-&gt;prepare($sqll)) or die(mysql_error());
  </code></pre>
  
  <p>Snapshot of articles table
  <img src="https://i.stack.imgur.com/4fdVI.png" alt="This is the articles table"></p>
  
  <p>Snapshot of votes table (currently no data in it)
  <img src="https://i.stack.imgur.com/JKHbA.png" alt="Votes table"></p>
  
  <p>Below is my full code</p>
  
  <pre><code>echo '&lt;form action="" method="post"&gt;';
  echo '&lt;select name="category" id="category" style="width:250px; background-color:lightgrey;"&gt;';
  echo    '&lt;option value="" disabled="disabled" selected="selected" "&gt;Select category&lt;/option&gt;';
  echo   '&lt;option value="My Testimony"&gt;My Testimony&lt;/option&gt;';
  echo    '&lt;option value="Love &amp; Relationships"&gt;Love &amp; Relationships&lt;/option&gt;';
  echo    '&lt;option value="Miscellaneous"&gt;Miscellaneous&lt;/option&gt;';
  echo '&lt;/select&gt;'; 
  echo    '&lt;input type="submit" name="a" value="Search"  style="margin-left:15px; margin-bottom:15px;"&gt;';
  echo '&lt;/form&gt;';
  
  
  //show after drop down value is selected
  if(isset($_POST['a'])){
  //echo "zeeshanaslamdurrani". "&lt;br&gt;";
  
  echo do_shortcode('[ujicountdown id="Photos Contest" expire="2015/04/30 00:00" hide="true" url="" subscr="sdf" recurring="" rectype="second" repeats=""]');
        global $wpdb;
  //get current competition value
  $cat =$_POST['category'];
          $comp = $wpdb-&gt;get_var("SELECT competition FROM competition ORDER BY cid DESC LIMIT 1");
  //echo $comp;
          $sql = "SELECT * FROM articles WHERE category='$cat'";
  
        $comp = $wpdb-&gt;get_var("SELECT competition FROM competition ORDER BY cid DESC LIMIT 1");
              echo "current competition is ". $comp;
  
  //test query
        $sqll = "SELECT articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title, Sum(zvotes.zvotes) AS votessum FROM articles LEFT JOIN zvotes on articles.aid=zvotes.aid GROUP BY articles.competition HAVING articles.category = '$cat' &amp;&amp; articles.competition = '$comp' ORDER BY votessum";
  
  $results = $wpdb-&gt;get_results($wpdb-&gt;prepare($sqll)) or die(mysql_error());
  
  foreach( $results as $result ) {
  echo '&lt;form action="" method="post"&gt;';
  echo "&lt;input name='category' type='hidden' value='$result-&gt;category'&gt;";
  echo $result-&gt;title.'&lt;br&gt;';
  echo "&lt;img src='$result-&gt;path' width='150' height='150' &gt;" . '&lt;br&gt;&lt;br&gt;';
  echo $result-&gt;body.'&lt;br&gt;';
  echo "&lt;input name='comp' type='hidden' value='$result-&gt;competition'&gt;";
  echo $result-&gt;username.'&lt;br&gt;';
  
  echo $result-&gt;votessum.'&lt;br&gt;';
  echo "&lt;input style='margin-bottom:30px;' value='vote' name='submit' type='submit'/&gt;&lt;/form&gt;";    
  
  }//end of foreach
  
  
  
  
  }//end of isset
  </code></pre>
  
  <p>I have a drop down on the top of the page and a search button as shown below on pressing search the results are shown but if I add duplicate values in username field of articles table I get only 1 row in result.
  My page<img src="https://i.stack.imgur.com/88r0l.png" alt="enter image description here"></p>