Single-table query of SQL statements

Source: Internet
Author: User

Syntax Order :

Select DISTINCT field 1, Field 2, Field 3 from library. Table

Where condition

GROUP BY group conditions

Having the filter # execution order, this step returns to running the SELECT statement before running the order by

Order by Sort Field

Limit n; # limits the number of bars to print to the screen

Where required before group BY, the aggregate function is not available

Hanving required after group BY, aggregate functions are available

An aggregate function, such as SELECT COUNT (ID), can be used after select from employee

Execution Order :

From->where->group By->having->distinct->order By->limit


Set mysql> set global sql_mode= "only_full_group_by"; #select只能取分组的字段

Select post from the employee group by post, but not select * FROM Employee GROUP by post;

# Group_concat

Link the value of a field in a record of group by, such as Select Post,group_concat (name) from the employee group by post;

# having

SELECT * from the employee GROUP by Post have the count (id) <2;


SELECT * from-Employee ORDER BY-age desc,id ASC;

# limit

SELECT * FROM Employee limit 0, 5;

SELECT * FROM Employee limit 5, 5; # pagination

Single-table query of SQL statements

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: 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.