SQL SELECT statement Usage

Source: Internet
Author: User

The SELECT statement is used to select data from the table.

The result is stored in a result table (called a result set).

SQL SELECT syntax
Select Column name from table name and:

SELECT * FROM table name NOTE: SQL statements are insensitive to case. Select is equivalent to select.
SQL Select instance
To get the contents of a column named "LastName" and "FirstName" (from a Database tutorial table named "Persons"), use a SELECT statement like this:

Select Lastname,firstname from persons

When you use the Select function, the equivalent of taking a set of qualifying records from a dataset and extending it in a cell, where each extended cell retains a pointer to the current record, the current row, so in the cell's subordinate cells, you should use the dataset name . column name to refer to the same record value of the same dataset, at which point the report engine does not need to retrieve the dataset for traversal, but instead takes a value directly from the current row.

Icon:

Typical Select usage:

Unreasonable usage:

Since there is a lot of data in a database that has a digital form, a very important use is to be able to do some operations on these numbers, such as aggregating them or finding their averages. SQL has functions that provide some of this kind. They are:


AVG (average)
Count (Count)
Max (max)
MIN (minimum value)
SUM (summation)
The syntax for using a function is:

Select "Function Name" ("Field name")
From "Table name"


For example, if we were to find the sum of sales fields from our demo table,

Store_information table
Store_name Sales Date
Los Angeles $1500 jan-05-1999
San Diego $ jan-07-1999
Los Angeles $300 jan-08-1999
Boston $700 jan-08-1999

We'll break in,


Select SUM (sales) from store_information

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.