Mysqlselect syntax _ MySQL

Source: Internet
Author: User
Syntax format of mysqlselect: select [option clause] field expression clause [from Clause] [where clause] [group by clause] [having clause] [order by clause] [limit clause]; tip: SequenceIs fixed

Select option clause[All | distinct]

This parameter mainly affects whether the query results contain duplicate records.

All: indicates that All records are retained. this default option can be omitted without writing.

Distinct: indicates removing duplicate records

Format: select all | distinct field expression from ...;

From clause

Format: from Data table

The FROM clause is used to specify the data source to be queried.

Multiple data tables can be separated by commas (,), and data tables can also be aliases.

If the data source is two tables, the result is a cross join method, and the number of records is equivalent to Cartesian product.

Total data in two tables = number of records in Table 1 * number of records in table 2

When writing *, the total number of field names is the sum of the number of fields in two tables.

The data table can also be an alias or a condition.

WHERE clause

Function is used to filter data.

Format: where condition expression

Conditional expressions use relational operators and logical operators

Relational operators

> Greater

<Less

> = Greater than or equal

<= Less than or equal

! = Not equal

<> Not equal

= Equal

Logical operators

& And

| Or

! Not

Xor exclusive or

Operator priority

The field alias cannot be used in the where clause.

Group by clause

It is mainly used for grouping. The grouping function is usually used in field expressions.

Format: group by field 1 [asc | desc], field 2 [asc | desc],...

By default, the sorting is positive sequence of asc.

When using count (*) and count (field name), note that the field value is null.

When count (field name) is used for statistics, null records are ignored!

HAVING clause

It is used to filter the query results again.

Obviously, the condition is used again for grouping query results.

When the where and group by clauses are omitted, having is not equal to where

You cannot place where in the having position.

ORDER Clause

It is mainly used to sort data.

Format: order by field 1 [asc | desc], field 2 [asc | desc],...

Asc indicates the positive sequence. it is the default option. if it is not written, it is asc.

Desc indicates reverse order

When a field is used for sorting, if a record with the same sorting field appears, the primary key is implicitly used for the second sorting.

LIMIT clause

This clause is paging.

Format: limit start record location, number of records

Note: If the starting record location is omitted, only the number of records is given, indicating that the content is retrieved from the first data.

Limit 10 is equivalent to limit 0, 10

Tip: The record position starts from 0.

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.