0

I just recently started learning SQL and MySQL. It's interesting but confusing. Here I have 3 queries; I am confused and can't get the differences in the queries because I get different output each time. Can you explain the exact meaning of the queries and what is the difference from each other.

Query 1:

SELECT CustomerID, Country
FROM Customers
GROUP BY Country
HAVING Count(CustomerID) >5;

Quesry 2:

SELECT Count(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING CustomerID >5;

Query 3:

SELECT Count(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING Count(CustomerID) >5;
Stu
  • 30,392
  • 6
  • 14
  • 33
Shah
  • 5
  • 1
  • Before getting accustomed to aggregations it's [worth reading this](https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html) – Stu Apr 01 '22 at 19:33
  • *I am confused and can't get the differences in the queries because I get different output each time.* Only query 3 is correct, queries 1 and 2 are errorneous. Enable `ONLY_FULL_GROUP_BY` SQL Mode and ensure. – Akina Apr 01 '22 at 19:37
  • This old answer of mine might help: https://stackoverflow.com/questions/13999817/reason-for-column-is-invalid-in-the-select-list-because-it-is-not-contained-in-e/13999903#13999903 – Bill Karwin Apr 01 '22 at 19:44

0 Answers0