Quick Start for SQL language (iii)

Source: Internet
Author: User
The most common use of SQL language in our day-to-day work is to query information from established databases. Next, let's look at how to implement various database query operations using SQL language.

SELECT ... From

For ease of explanation, we create the following datasheet named Store_information in the database.

Store_information

Store_name

Sales

Date

Los Angeles

$1500

jan-10-2000

San Diego

$

jan-11-2000

Los Angeles

$300

jan-12-2000

Boston

$700

jan-12-2000

The simplest command for database queries in the SQL language is select ... From, the syntax format is:

Select "COLUMN_NAME" from "table_name"

For example, if we want to query all store names in the Store_information datasheet, you can use the following command:

SELECT Store_name from Store_information

The query results appear as follows:

Store_name

Los Angeles

San Diego

Los Angeles

Boston

If the user wants to query more than one field at a time, you can separate the field names you want to query by adding them to the SELECT keyword in the middle.

DISTINCT

The Select keyword enables users to query all the data for a specified field in a data table, but it can sometimes be unavoidable that duplicate information is present. You can use the DISTINCT keyword in the SQL language if you want to query only for information that has a different record value. The syntax format is as follows:

Select DISTINCT "column_name"

From "table_name"

For example, we can use the following command to query all records with different record values for the Store_information datasheet.

SELECT DISTINCT store_name from Store_information

The results of the query are as follows:

Store_name

Los Angeles

San Diego

Boston

WHERE

In addition to selecting records with different record values, sometimes we might want to query the data in the database based on certain criteria. For example, we might want to query a store that has a sales volume of more than 1000 dollars in the Store_information datasheet. To do this, we can use the SQL language where keyword to set the query criteria. The syntax format is as follows:

Select "Column_name"

From "table_name"

WHERE "Condition"

As a result, we can use the following command to query store information for more than 1000 dollars:

SELECT store_name from store_information WHERE Sales > 1000

The query results appear as follows:

Store_name

Los Angeles

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.