title: select query to get all values and also distinct value
body: <p>Hi i am trying to get distinct values and some other data from same table A . the code i tried is</p>
  
  <pre><code>$query2="select DISTINCT(from_id) from messages where to_id='$userid' order by messagedate DESC";
  $res2=mysql_query($query2);
  while($row2=mysql_fetch_row($res2))
  {
  $query="select * from messages where to_id='$userid' and from_id='$row2[0]' ORDER BY messagedate DESC"
  </code></pre>
  
  <p>using the above method i am unable to filter distinct values hence i tried like this </p>
  
  <pre><code>select msgid,DISTINCT(from_id) from messages where to_id='21' order by messagedate DESC
  </code></pre>
  
  <p>Its an error. need help pls</p>