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:
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