Skip to main content

Order Operation SELECT MySQL

Many people may not know how MySQL has the sequence of the SELECT statement that we use. And many others as well, probably asking me, why do we know it (FA)

In the official program Determining the order of work, It is very important. Determining the correct order will result in the result being incorrect. It may cause the result to be incorrect, such as multiplying 2 + 5 * 3 multiplying before adding. Will get the result 17, but if adding before multiplying Will get a result of 21 which is not equal As for the result, it will be correct depending on the problem. Which we have a way to force the result to be always correct with the work order such as

SELECT 2 + 5 * 3 และ SELECT 5 * 3 + 2

The result will always be 17 since MySql will always execute * before +. Therefore, if the correct result is 21, then this calculation will be wrong. Control results are always accurate by placing parentheses around the order in which MySQL will calculate the results from

Innermost bracket -> outermost bracket such as

SELECT (3 * (2 + 5) ) = SELECT (3 * (7) ) = 21

And for the same hierarchy Will be processed from left to right, for example

SELECT (2 + 5) * 3 = SELECT 7 * 3 = 21
SELECT (2 + 5) * ( 3 * 1 ) = SELECT (7) * (3 * 1) = SELECT (7) * (3) = 21

A bit out-of-focus, back to the work order of SELECT

SELECT .....
FROM ......
[WHERE .....]
[GROUP BY .....]
[HAVING ......]

  1. For the first time, MySQL will process at the FROM line to select the database first, including various JOIN commands (if any) to select the data from JOIN first.
  2. Next, if there is a WHERE clause, MySQL will continue processing from this command. In which the processing processes orders from left to right Determining the order of comparison in this section It is very important to the result. If wrongly determined, the result may not be correct, with various priority rules. Will meet the requirements of MySQL, but in practice we should choose a query that gives results Least left On the left-hand side and query which gives more results On the right-hand side.
  3. The GROUP BY statement will be processed next (if any) to group the table according to the specified conditions.
  4. HAVING will be processed further To filter the results from GROUP BY again
  5. Finally, SELECT will work to select the desired column according to the statement

Comments

Popular posts from this blog

Changing AppServ Path Directory

Usually when we install AppServ on our machine Important instructions for installation are Use the given value in the program as the best, which will allow us to The directory that stores files on our device is "C:\AppServ\www" which, if we want to change this file store to another place Let us do as follows Go to Start Menu -> Programs -> AppServ -> Apache Configure Server -> Edit the Apache httpd.conf Configuration File. Clicking will open the file httpd.conf and edit it with NotePad. Let us use Replace to search and replace. "C:/AppServ/www" with the new directory name that we want. For example, "D:/www", every character is assigned to the new directory "D:\www" After that, save the file to the same name and then restart the Apache is complete. Now that we have a new directory that holds our files as "D:\www" as needed, let us put the index.php file into this directory. And then test by typing http://l...

Create Multiple Domains on Localhost

Usually, when we install Appserver, we will get the domain name is  http://localhost  If we want to change to a different name, such as  http://project  Or when wanting to have multiple domains to use with multiple projects, what to do? For example,  http://project1  Keep the file in the project1 directory and  http://project2  Keep files in project2. Managing or testing is probably a lot easier. Especially if there are many projects and the work will be a lot easier The basic principle is similar to making a subdomain on localhost : 1. Open the file  C:\windows\system32\drivers\etc\hosts  with a general text editor and add the desired domain, such as 127.0.0.1 project1 127.0.0.1 project2 And save Can be added according to the number of projects desired And the desired name (Including being able to create subdomain too) 2. Open Appserver's httpd.conf file. Don't know where it is. You can look at the Appserv...

Console API In JavaScript

From system development using JavaScript and NodeJS Found that using the command console.log() is a lot Often, the result is not as desired. Therefore introducing a little more Console Console usage Let's get started. Basic Console API In JavaScript Most will find in the debug of the work system as follows. console.log () encountered the most. console.warn () console.error () Let's look at some other useful methods. 1. Console.table() Display data of objects and arrays in a tabular format. Which is easy to read and easy to understand. 2. Console.assert() Check the submitted value to be true or false. If the value entered is false and will write a log for us to see But if true it will not display the log The false value consists of 0, false, blank, etc. 3. Console.count() For counting values or counting work times Very useful when we debug a system. Especially those with a strange life cycle will make us understand work more easily Which will be used to...