title: Using JOINs and group by together in single sql query
body: <p>I'm not able to use JOINS and group-by together:
  I searched for this...but I didn't find the solution..Problem is as below:</p>
  
  <p>I have two tables, first is <code>main_table</code> with fields <code>eid</code>, <code>name</code>, <code>status</code></p>
  
  <p>Second table is followups with fields <code>fid</code>, <code>eid</code>, <code>last_date</code>, <code>remarks</code>, and <code>next_date</code></p>
  
  <p>Second table is used to store followup details of clients (client details stored in main_table) and i want to get last followup record for each client with selected date period (from_date to to_date) and sort by next_date in descending order.</p>
  
  <p>i used the below query but not working</p>
  
  <pre><code>SELECT * 
  FROM main_table as MT 
  JOIN followups as MF on MT.eid=MF.eid 
  WHERE MT.status='open' AND MF.NDate&lt;='2012-12-07' 
  GROUP BY MF.eid 
  ORDER BY MF.next_date DESC
  </code></pre>
  
  <p>thanks in advance...guys</p>