MySQL Max and where execution issues
Execute SQL:
CREATE TABLE ' grades ' (
' ID ' int (a) is not NULL auto_increment,
' student_id ' int (a) is not NULL,
' Subject ' varchar (COLLATE) Utf8_bin DEFAULT NULL,
' Grades ' varchar (COLLATE) Utf8_bin DEFAULT NULL,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=4 DEFAULT Charset=utf8 collate=utf8_bin;
Insert INTO ' grades ' (' id ', ' student_id ', ' Subject ', ' grades ') VALUES (1, 1, ' language ', ' 80 '), (2,1, ' math ', ' 89 '), (3,2, ' language ', ' 90 ');
CREATE TABLE ' Student ' (
' ID ' int (a) is not NULL auto_increment,
' Name ' varchar (COLLATE) Utf8_bin DEFAULT NULL,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=4 DEFAULT Charset=utf8 collate=utf8_bin;
INSERT INTO ' student ' (' id ', ' name ') VALUES (1, ' xiaoming '), (2, ' Xiaohong '), (3, ' Xiaobai ');
Execution Result:
Execution Result 1:
Execution Result 2:
Execution Result 3:
Execution Result 4:
Execution Result 5:
Thus:
1.max is performed before the Where condition,
2. And group by is also executed before Max
3. When where and group by occur the precedence of the Where condition
MySQL Max and where execution issues