sql - Give all rows appear in another table at least specific number of times -


i using sample database , want write query on tables customers , orders gives customers have made more 2 orders. although achive query:

select customers.* customers customers.customerid in( select orders.customerid orders group orders.customerid having count(*)>2 ); 

i cannot understand why query:

select customers.* orders inner join customers on orders.customerid=customers.customerid group customers.customerid having count(*)>2; 

cannot give same results. message database is:

"cannot group on fields selected '*' (customers)."

i had though impression should work, since customers.customerid included on demanded columns in select statement. problem , how modify second query in order work, though excecutes superfluous statements?

from sql group statement

the group statement used in conjunction aggregate functions group result-set 1 or more columns.

sql group syntax  select column_name, aggregate_function(column_name) table_name column_name operator value group column_name; 

so using aggregating, need specify columns aggregating by, , cannot use *

you have specify columns in both select , group by clauses.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -