SQL must know

Source: Internet
Author: User

Tables (table)

Column (COLOMN)

Rows (Row)

Primary key (primary key)

The row that uniquely identifies each row in the table is called the primary key. The values in the primary key column are not allowed to be modified or updated.

Sql:

Structured query Language, structured querying language.

Case insensitive. For readability, the SQL keyword is capitalized, with all columns and table names lowercase.

Whitespace is ignored, so SQL can be divided into many rows.

  

SELECT

Retrieving data

SELECT prod_id, Prod_name, Prod_price  from Products ; -- Use the SELECT statement to select data from table products, specify 3 column names, and separate the column names with commas. 

Output:

prod_id    prod_name        prod_price----------------------------------------------------     BNBG01     Fish bean bag toy   3.4900
...

The FROM keyword indicates the name of the table from which the data is retrieved.

Sort Retrieve data

Clauses (clause) are usually made up of a keyword and data.

ORDER by,

Order: The last clause in the SELECT statement should be guaranteed.

Sort multiple columns:

Sort the results first by two columns, first price, then name.

SELECT prod_id, Prod_price, Prod_name  from  Products ORDER  by Prod_price, Prod_name;

Sort By column location:

SELECT prod_id, Prod_price, Prod_name  from  Products ORDER  by 2,3;

Descending order:

ORDER  by DESC

Ascending is the default.

Filtering data

WHERE

SQL must know

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.