The problem of the execution order of mysql statements

1. I use a sql statement

of select b from table where billing 1 groupby c having d > 2 orderby b desc .

2. At first, I thought the reason for reporting an error was that I thought that the order in which mysql is executed is from where groupby select having orderby
, so the data has been filtered out before having execution. There is no d field in the data, so using having d > 2 will report an error because having did not have this field
but actually did not report an error. Before that, I remember that I also tested that it was wrong, and now I don"t know what happened. at first I thought it was a version problem. The version I"m testing now is mysql

.

3. I read the document on mysql"s official website and did not understand , and then found a lot of answers online. There are all kinds of from where group having select orderby , and I don"t know to believe that now.

4. So ask the great gods about the order in which the sql of mysql executes sentences.

Mar.18,2021

. You read it correctly. There was an article written in order, but I forgot it, so I might as well come up. First, from determines the fields you need, and second, where filters the data, so where plays an important role in improving performance. This is a virtual table that has already been generated, and there is no column d when there is no having.


I think it is the reason for from where select group having orderby as follows:: from where select first finds the data to group grouping, then having filtering and then orderby sorting

Menu