MySQL Max and where execution issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.