Basic SELECT statement syntax in MySQL

Source: Internet
Author: User
Tags mysql functions

The basic syntax of the SELECT statement in MySQL is:

The following is a reference clip:

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]

From this basic syntax, we can see that the simplest SELECT statement is SELECT select_list. In fact, you can use this simplest SELECT statement to complete many functions you want, first, you can use it to perform any operations supported by MySQL. For example, SELECT 1 + 1 returns 2. Second, you can also use it to assign values to variables. in PHP, with this feature of SELECT statements, you can freely use MySQL functions to perform various operations for PHP programs and assign values to variables. In many cases, you will find that MySQL has many more powerful functions than PHP.

STRAIGHT_JOIN, SQL _SMALL_RESULT, SQL _BIG_RESULT, and HIGH_PRIORITY are extensions of MySQL to ANSI SQL92. If the optimizer joins tables in a non-optimal order, use STRAIGHT_JOIN to speed up the query.

SQL _SMALL_RESULT and SQL _BIG_RESULT are a set of relative keywords. They must be used with group by, DISTINCT, or DISTINCTROW. SQL _SMALL_RESULT tells the optimizer that the result will be very small. MySQL is required to use a temporary table to store the final table instead of using sorting. On the contrary, SQL _BIG_RESULT tells the optimizer that the result will be very small and MySQL is required to use sorting instead of creating.

HIGH_PRIORITY will give the SELECT statement a higher priority than the statement for updating the table, so that it can perform a quick query with priority.

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

DISTINCT and DISTINCTROW provide a basic but useful filter for the returned result set. That is, only non-duplicate rows are included in the result set. Note that for keywords DISTINCT and DISTINCTROW, NULL values are equal, no matter how many NULL values there are, select only one. The use of "ALL" is too confusing. It has no effect on the generation of result sets.

INTO {OUTFILE | DUMPFILE} 'file _ name' export_options to write the result set to a file. Files are created on the server host and cannot exist. The syntax of the export_options section in the statement is the same as that in the FIELDS and LINES clauses used in the load datainfile statement. We will discuss it in detail in the MySQL advanced _ load data section. The keyword difference between OUTFILE and DUMPFILE is that only one row is written to the file before, and no column or row ends.

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.