MySQL Data Retrieval Select -- MySQL must know Reading Notes (1)

Source: Internet
Author: User

1. Select to retrieve a single column

SELECT column name From Table Name
When the output data is not sorted, the order is not certain.

2. Select to retrieve multiple columns

SELECT column name, column name 1, column name 2 FROM Table Name

3. Retrieve all columns

SELECT * FROM Table Name

Generally, you are advised not to use the wildcard * unless you really need each column in the table *. This will reduce the search and application performance.

4. Retrieve different rows

Use DISTINCT keywords

Select distinct column name FROM Table Name
If select distinct column name 1 and column name 2 FROM table name, all rows will be retrieved unless the two columns are different. That is to say, the data of all two columns is retained.

5. Restrict returned results

SELECT column name FROM table name LIMIT 5;
Indicates that no more than five rows are returned.

SELECT column name FROM table name LIMIT;

Equivalent

SELECT column: FROM Table Name: LIMIT 5 OFFSET 100;
Returns the five rows starting with row 100. The first number is the start position, and the second number is the number of rows to be retrieved.

Note: Row 0 retrieves the first row 0 instead of Row 1. Therefore, LIMIT1 and 1 retrieve the second row instead of the first row.

6. Use a fully qualified table name
SELECT prosucts. prod_name FROM crashcourse. prosucts;



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.