0

What is happening when using another column in SELECT than in the GROUP BY statement?

eg

SELECT Name from Employee GROUP BY City

It seems that the size of the output depends on the unique City elements and if you are having more than one Name per City, it seems that only the first name will be returned.

What is the meaning behind such a phrase and why is it working?

I tried the statement SELECT CustomerName FROM Customers GROUP BY City;at the W3S SQL sandbox

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
JohnDizzle
  • 1,268
  • 3
  • 24
  • 51
  • `It seems that the size of the output depends on the unique City elements and if you are having more than one Name per City, it seems that only the first name will be returned` -- Sounds like you already completely understand it. – Robert Harvey Jan 30 '19 at 18:01
  • The syntax says that I have to use the same column as I use for GROUP BY for SELECT. So I'm still curious why the code above is working – JohnDizzle Jan 30 '19 at 18:04
  • 1
    Note that W3Schools uses [WebSQL](https://www.w3.org/TR/webdatabase/) to demonstrate SQL. WebSQL might not be totally compliant with the ANSI SQL specification. – Robert Harvey Jan 30 '19 at 18:09

0 Answers0