MySQL Query Statement Execution order

Source: Internet
Author: User
Tags mysql query

MySQL query statements are divided into 11 steps, each of which will produce a virtual table, the virtual table as a processing input, but these virtual tables are transparent to the user, but only the last virtual table will be returned as the result.

Statement execution Order:

Order

Name

Content

1

SELECT

Command initiation

2

* or AVG (field), etc. Query content

3

From

Query location

4

WHERE

Conditional query

5

GROUP by

Group

6

Having

Screening

7

ORDER by (ASC/DESC)

Sort

8

LIMIT

Limit the number of results

1. Single-table query

    • Querying the specified column
-- Check the student's form for the number and name; Select  from student;
    • Query all Columns
-- Check all information in student tables   from  student;
    • To alias a column after a query
-- Check the "name" and "Year of birth" columns for all students Select  as name, as from student;
    • Single-Condition Query
-- query position is a  record of salesman;Select*fromwhere job='  Salesman'
    • Multi-Criteria Query
--Query department records in 10 or 20Select *  fromEmpwhereDeptno=Ten orDeptno= -;--Query Department in 10 or department at 20 and salary less than 2000 recordSelect *  fromEmpwhereDeptno=Ten or(Deptno= -  andSal<= -);

Go to re-query, use <DISTINCT column name > statement

-- Check the student number of the course Select distinct  as  from score;
    • Query null value (NULL)
 --  query No course number and course name for the first course.  select  Cno as  course number, Cname as  course name, cpno from  course  where  cpno is  null  ;  --  Check all students with grades, course numbers and grades  select  Sno as , Cno as  course number, Grade as  score from  SC where  Grade is  not  null ; 
    • Convert NULL to actual value, using <COALESCE (column name, replace value) > statement
-- query allowance is null, replaced by 0 Select COALESCE (Comm,0 from EMP;
    • The fuzzy query (like% _ statement)% denotes any character; _ Represents a single character
--query employee names starting with a recordSelect *  fromEmpwhereEname like 'a%';--Query the employee name for a record that contains aSelect *  fromEmpwhereEname like '%a%';--Query Employee Name The second letter begins with a recordSelect *  fromEmpwhereEname like '_a%';

MySQL Query Statement Execution order

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.