Select distinct in SQL?
<p>The select distinct not working and the count(*) is not selecting the number of grouped rows but it is selecting the duplicate msg_contents.Please help..
I wanted to select distinct username and the number of duplicate usernames.</p>

<pre><code>&lt;?php
require_once"cnc.php";

$sort = "SELECT hate_p FROM hate_t";
$qry = mysql_query($sort);
while($fet = mysql_fetch_assoc($qry)) {
    if($fet == 0) {
        echo "No Entries";
    } else {

        $sql = mysql_query("
            SELECT DISTINCT
                username,
                msg_content,
                COUNT(*) c
            FROM messages
            WHERE msg_content LIKE '%".$fet['hate_p']."%'
            GROUP BY username HAVING c&gt;0"
        );

        while($messages = mysql_fetch_assoc($sql)) {
        ?&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;?php echo $messages['username'];?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $messages['c'];?&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;?php
        }
    }
}
?&gt;
</code></pre>