MySQL advanced query

Source: Internet
Author: User

Advanced query:

1. Connection Query

SELECT * FROM Info,nation #得出的结果称为笛卡尔积
SELECT * from info,nation where info.nation = Nation.code

Join on connection

SELECT * from Info join Nation #join连接
SELECT * from Info join Nation on info.nation = Nation.code


2. Joint queries

Select Code,name from Info
Union
Select Code,name from Nation


3. Sub-query

1) Unrelated subqueries

Select Code from Nation where Name = ' Han ' #去Nation表中查询汉族的民族代号

SELECT * from Info where Nation = (ethnic code) #在Info表中查询民族代号为上一个查询结果的所有信息

SELECT * from Info where Nation = (select Code from Nation where Name = ' Han ')

The results of a subquery query are used by the parent query, and the subquery can be performed independently as a non-subquery

2) Related sub-query

SELECT * from Car where oil< (average fuel consumption for this series) #查询油耗小于该系列平均油耗的

Select AVG (oil) from Car where Brand = "value" #查询某系列的平均油耗

SELECT * from Car a where oil< (select Avg. from car b where B.brand = A.brand)

MySQL advanced query

Related Article

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.