title: MySQL Query - grouping issue
body: <p>So this is my query</p>
  
  <pre><code>select 
  A.search_parameters,
  reseller_count,
  reseller,
  num
  
  from 
  
  (select 
   search_parameters,
   count(distinct(reseller)) as reseller_count 
   from all_lookups 
   group by search_parameters)A
  
   join
  
   (select
    search_parameters,
    reseller,
    count(*) as num
    from all_lookups
    group by reseller,search_parameters)B
  
    on A.search_parameters=B.search_parameters
  
    where a.search_parameters not like '%addsomekeywords%' 
    and a.search_parameters not like '%add-some%' 
    order by reseller_count DESC,num 
    DESC limit 1000
  </code></pre>
  
  <p>For some reason, the results are grouped by reseller_count, but I want them to be grouped by search_parameters.  I've tried adding a group by A.search_paramters after the where clause but this creates the error
  'select list expression not produced by aggregation output (missing from GROUP BY clause?)'
  It might also be important to note that I am using this query in Cloudera Impala but I suspect the same MySQL rules/syntax still apply</p>
  
  <p>Here is an example of what I am getting</p>
  
  <pre><code>A.search_parameter|reseller_count|reseller|num
  hello             | 2            | abc    |556
  hi                | 2            | tre    |54
  hello             | 2            | xyz    |9
  hi                | 2            | ytu    |4
  </code></pre>
  
  <p>and what I want is</p>
  
  <pre><code>A.search_parameter|reseller_count|reseller|num
  hello             | 2            | abc    | 556
  hello             | 2            | xyz    | 9
  hi                | 2            | tre    | 54
  hi                | 2            | ytu    | 4
  </code></pre>
  
  <p>So basically, all of the search_parameters' with the same reseller_count are randomly put together, but I want them grouped by search_parameter</p>
  
  <p>Thanks</p>