Last answered:

10 May 2023

Posted on:

20 Apr 2023

0

query seems incorrect

select * from salaries  group by emp_no; - I don't think this is a correct syntax. Don't we need an aggregate function to use with GROUP BY statement? Otherwise how will SQL know which salary to put for each emp_no? 

3 answers ( 0 marked as helpful)
Instructor
Posted on:

21 Apr 2023

1

Hi Eugenia!
Thanks for reaching out.


Actually, the query is correct. It returns the first salary for every employee because Workbench does not know what to return. This is very typical approach - it is returned the first matched value for the column we use in the GROUP BY clause.


Hope this helps.
Best,
Tsvetelin

Posted on:

21 Apr 2023

0

In my workbench when I execute the query I get an error message:

Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'employees.salaries.salary' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Instructor
Posted on:

10 May 2023

0

Hi Eugenia!
Thanks for reaching out.


To make sure you can take some of the remaining lectures of the course without unnecessary interruption, we strongly advise you to execute the following query now.

set @@global.sql_mode := replace(@@global.sql_mode, 'ONLY_FULL_GROUP_BY', '');

You have to restart the Workbench afterwards in order to save the new settings.


Hope this helps.
Best,
Tsvetelin

Submit an answer