SQL SELECT Statement

Source: Internet
Author: User

Basic SELECT Statement

SELECT*| {[DISTINCT] column|expression [alias],...}

fromtable;


. Select identifies which columns are selected.

. From identifies the table from which to select.


1. Select selects all columns or select specific columns;

All columns: SELECT * from departments;

Specific columns: SELECT department_id, location_id from departments;


Attention:

    • SQL language is not case sensitive.

    • SQL can be written in one line or multiple lines

    • Keywords cannot be abbreviated or branch

    • The clauses are usually written in branches.

    • Use indentation to improve the readability of the statement.


2. Binding operator (+-*/)

Operator Precedence (*/+-), parentheses, the operation in parentheses is performed first.

Example: SELECT last_name, Salary, 12* (salary+100) from employees;


3. Using aliases

Alias for column:

    • Renames a column.

    • Easy to calculate.

    • Immediately following the column name, you can also add the keyword ' as ' between the column name and the alias, using double quotation marks to include spaces or special characters in the alias and case sensitivity.

Example 1:

SELECT last_name as name, commission_pct comm from employees;

Example 2:

Select Last_Name "Name", salary*12 "annual salary" from employees;


4. Connector | |

Connector:

    • Concatenate columns and columns with characters.

    • Use ' | | ' Said.

    • can be used to ' synthesize ' columns.

As: System.out.println (123 + "Hello" + 123);//123hello123

Example: SELECTlast_name| | job_id as "Employees" from Employees;

Example: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6F/C2/wKioL1WngP-ToahvAADpgXuMbtA057.jpg "title=" Picture 1.png "alt=" Wkiol1wngp-toahvaadpgxumbta057.jpg "/>

5. String

    • The string can be a character, a number, a date in the SELECT list.

    • Dates and characters can only appear in single quotation marks.

    • Each time a row is returned, the string is output once

Example: SELECT last_name| | ' is a ' | | job_id

As "Employee Details"

From employees;

Example: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/C4/wKiom1Wnf9byEHU2AAEAO6ujfvM047.jpg "title=" Picture 2.png "alt=" Wkiom1wnf9byehu2aaeao6ujfvm047.jpg "/>

6. Delete duplicate rows

Delete duplicate rows using the keyword ' DISTINCT ' in the SELECT clause.

Example:

SELECT DISTINCT department_id

From employees;



This article is from the "Test Road" blog, be sure to keep this source http://yangliqin.blog.51cto.com/8836122/1675405

SQL SELECT Statement

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.