title: postgreSQL select additional columns that aren't used in aggregate function
body: <p>I'm trying to write a query in PostgreSQL and I'm getting a little frustrated because it works in other database engines. I need to select the top 5 users from a given joins table like this:</p>
  
  <pre>
  SELECT users.*, 
         COUNT(deals.id) AS num_deals 
  FROM users, deals 
  WHERE deals.users_id = users.id 
  GROUP BY users.id 
  ORDER BY num_deals LIMIT 5;
  </pre>
  
  <p>I need the top 5 users. This code works in sqlite, mysql, etc, yet PostgreSQL refuses to select additional fields that aren't used in aggregate functions. I'm getting the following error:</p>
  
  <pre><code>PGError: ERROR:  column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
  </code></pre>
  
  <p>How can I do this in PostgreSQL??</p>