SQL Basic Keyword Function association connection

Source: Internet
Author: User

Some SQL in the http://www.w3cschool.cn/sql_having.html

1 ORDER by sort

SELECT  from ORDER  by Company;

2 distinct de-weight

SELECT DISTINCT  from Orders;

3 Limit control number of selected bars (MYSQL)

SELECT *  from  5;

ORACLE

SELECT *  from WHERE <= 5;

4 wildcard characters

SELECT *  from  WHERElike'c_r_er'--  _ represents a character 
SELECT *  from WHERE  like ' [aln]% ' -- A% beginning with a or L or N represents one or more characters SELECT *  from WHERE  like ' [! aln]%'--  not starting with a or L or n

5 between

SELECT *  from WHERE  not between ' Adams '  and ' Carter ';

6 Union and UNION ALL

Employees_china:
e_id E_name
01 Zhang, Hua
02 Wang, Wei
03 Carter, Thomas.
04 Yang, Ming
Employees_usa:
e_id E_name
01 Adams, John.
02 Bush, George.
03 Carter, Thomas.
04 Gates, Bill.
SELECT  from Employees_china UNION SELECT  from Employees_usa;

Results
E_name
Zhang, Hua
Wang, Wei
Carter, Thomas.
Yang, Ming
Adams, John.
Bush, George.
Gates, Bill.

Two table Overlay Union is more than union all a row weight operation

7 Internal Connection External connection

A table                b
ID name ID
1 a 1
2 b 3 C
4 C
The inner connection is the same data as the left table and the right table, and the query results have only equal data:
SELECT * FROM A inner join B on A.id=b.id
SELECT * from a b where a.id=b.id

ID Name ID Name
1 a 1 b
Outer joins: Left outer connection, right outer connection, full outer connection
Left outer connection is to left table, to match the right table, the left table has how many data, the result is how many data
SELECT * from A LEFT join B on A.id=b.id
ID Name ID Name
1 a 1 b
2 b NULL NULL
4 c NULL NULL
The right outer connection is connected with the left outer connection, in contrast, to the right table, to match the left table, the right table has how many data, the result is how many data
SELECT * from A right join B on A.id=b.id
ID Name ID Name
1 a 1 b
NULL NULL 3 C
Total outer JOIN Data bar number is not necessarily, quite with is the left outer connection and the right outer joins the synthesis
SELECT * from A full join B on A.id=b.id
ID Name ID Name
1 a 1 b
2 b NULL NULL
NULL NULL 3 C
4 c NULL NULL

8 UNIQUE constraint constraint also has primary key foreign key default check (id>0, etc.) is not empty
CREATE TABLEPersons (id_pint  not NULL, LastNamevarchar(255) not NULL, FirstNamevarchar(255), Addressvarchar(255), Cityvarchar(255),UNIQUE(id_p))--constrain MYSQL when building tables
CREATE TABLEPersons (id_pint  not NULL UNIQUE, LastNamevarchar(255) not NULL, FirstNamevarchar(255), Addressvarchar(255), Cityvarchar(255)) --ORACLE

9 Index

CREATE INDEX  on DESC);

The role and advantages of database indexing disadvantages

10

SQL Basic Keyword Function association connection

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.