I understand that ANSI SQL requires non-GROUP BY attributes to be SELECTed with aggregate function.
For example, below is invalid in ANSI SQL:
SELECT name, MAX(salary), dept
FROM `employee_gb`
GROUP BY dept;
as name
is not passed to any aggregate function.
However, MySQL allows this. If we want MySQL to behave like ANSI SQL, we need to set sql mode as explained here. But when I tried that, it still gave me no error:
SET GLOBAL sql_mode = 'ANSI';
I guess above query should give me error. What I am missing here?
Below are queries to populate data:
CREATE TABLE `employee_gb`
(name varchar(50), salary float, dept varchar(50));
INSERT INTO `employee_gb` VALUES('a',1,'dept3');
INSERT INTO `employee_gb` VALUES('b',2,'dept4');
INSERT INTO `employee_gb` VALUES('c',3,'dept1');
INSERT INTO `employee_gb` VALUES('d',4,'dept2');
INSERT INTO `employee_gb` VALUES('e',5,'dept2');
INSERT INTO `employee_gb` VALUES('g',5,'dept2');
INSERT INTO `employee_gb` VALUES('f',6,'dept1');
These are some screenshots for execution from CLI: