The basic syntax of SELECT statement in MySQL

Source: Internet
Author: User
Tags sort

The basic syntax for a SELECT statement in MySQL is:

The following is a reference fragment:

SELECT [Straight_join] [Sql_small_result]

[Sql_big_result] [High_priority]

[distinct| distinctrow| ALL]

Select_list

[Into {outfile| DumpFile} ' file_name ' export_options]

[From Table_references [WHERE where_definition]

[GROUP by Col_name,...] [Having where_definition]

[Order BY {Unsighed_integer|col_name|formura} [asc| DESC],...]

[LIMIT [Offset,] rows] [PROCEDURE Procedure_name]]

As you can see from this basic syntax, the simplest SELECT statement is the select select_list, and you can actually use the simplest SELECT statement to do many of the things you expect, and you can use it for any operation that MySQL supports, for example: SELECT 1+1, it will return 2; second, you can also use it to assign values to variables, and in PHP, using the function of the SELECT statement, you are free to use MySQL's functions to perform various operations on the PHP program and assign values to variables. In many cases, you will find that MySQL has many functions that are more powerful than PHP.

Straight_join, Sql_small_result, Sql_big_result, high_priority are MySQL extensions to the ANSI SQL92. If the optimizer joins tables in a non optimal order, using Straight_join can speed up the query.

Sql_small_result and Sql_big_result are a set of relative keywords. They must be used in conjunction with group BY, distinct, or distinctrow. Sql_small_result told the optimizer that the results would be small, requiring MySQL to use temporary tables to store the final tables instead of using the sort; instead, Sql_big_result told the optimizer that the results would be small, requiring MySQL to use sort instead of temporary tables.

High_priority will give the select a higher priority than a statement that updates the table, making it possible to make a quick query first.

The use of the above four keywords is indeed more obscure. Fortunately, in most cases, we can choose not to use these four keywords in mysql.

DISTINCT, Distinctrow provides a basic but useful filter for the result set returned by the query. That is, the result set contains only distinct rows. Note here that for the keyword distinct, distinctrow, null values are equal, no matter how many null values, select only one. And all the use of the superfluous suspicion. It has no effect on the production of the result set.

into {outfile| DumpFile} ' file_name ' export_options to write a result set to a file. The file is created on the server host and cannot be already present. The syntax for the export_options part of the statement is the same as in the fields and lines clauses used in the LOAD datainfile statement, which we will discuss in detail in the MySQL Advanced _load data section. The difference between outfile and DumpFile is that you write only one line to the file, and no columns or rows end.

Related Article

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.