How to group by when querying duplicate records?
SELECT
  *
FROM 
  foos 
  INNER JOIN 
  (
    SELECT
      name
    FROM 
      foos 
    GROUP BY 
      name 
    HAVING 
      COUNT(*) &gt; 1 
  ) AS dup
  ON foos.name = dup.name
ORDER BY 
  name