MySQL Basics Getting Started learning "7" Query expression parsing select

Source: Internet
Author: User

1. Find records:

SELECT select_expr [, select_expr ...]

[

From Table_references

[WHERE Where_condition]

[GROUP by {col_name | postion} [asc| DESC],...]

[Having where_condition]

[ORDER by {col_name | expr | position} [ASC | DESC],...]

[LIMIT {[offset,] row_count | row_count offset Offset}]

]

Evaluate the result of an expression

(1) query expression: select_expr

Each expression represents the desired column and must have at least one;

Multiple columns are separated by commas;

An asterisk (*) indicates all columns. Tbl_name.* can represent all columns of a named table;

A query expression can use [as] alias_name to give it an alias;

Aliases can be used for a group by, an ORDER by, or a HAVING clause.

You can also make the current column of data not in the same order as the original table

The order of the SELECT statement query expressions affects the order of the results

When you use a multi-table connection later, two different tables may have the same field, and if you write directly, you can't tell which data table it belongs to.

Sometimes the names of certain fields are very long and may not be easy to remember, and we can give them aliases.

the alias of the field will also affect the field name of the subsequent result set.

As can be omitted: (in general, it is better to write as)

(2) Where statement for conditional query:

Conditional expression: Filters The record and displays all records if no WHERE clause is specified;

In the where expression, you can use the functions or operators supported by MySQL.

(3) Group BY statement groups query results:

[GROUP by {col_name | position} [ASC | DESC],...]

You can specify either the column name of the column (common), or the position of the column (which is the position of the field in the SELECT statement, starting at 1), ascending (default) or descending, and multiple grouping conditions separated by commas.

(4) Having a statement sets the grouping condition :

To group only a subset of records: [Having where_condition]

It is important to ensure that the condition of the grouping is either an aggregate function (Max/min/avg/sum/count ..., always only one return result), or that the field must appear in the current SELECT statement.

(If you got some expression#1 error, see 78664267)

(5) Order BY statement sorts the result of the query: [ORDER by {col_name | expr | position} [ASC | DESC],...]

Sort by two fields at the same time: first to see whether the first field can discharge the desired results, if it is possible to ignore the second field directly, otherwise follow the second field or even the third field and so on:

(6) Limit statement limits the number of query results returned:

[LIMIT {[offset,] row_count | row_count offset Offset}]

The first form of grammatical structure is more common

By default, all the results you want to find are returned.

In the future, using PHP for paging will use this statement to achieve the paging effect. The offset formula is (current page-1) * The number of records displayed per page.

Returns from line 1th and returns 2 records.

Starting from the 3rd record, return 2. The record is numbered starting from 0!!!

Note that the ID number in our example has no relation to the order in the result set, as long as it is in the first position in the result set, it corresponds to 0, and the second position corresponds to whether the 1...,id number is 100 or 1000.

MySQL Basics Getting Started learning "7" Query expression parsing select

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.