Sub-query (most difficult)

Source: Internet
Author: User

  1. The so-called subquery is the embedding of several small queries within a query.

  2. Grammar:

    Select "Distinct" * | column name "Alias", Column name "Alias" ... | Statistical functions, (

    select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
    From data table "alias", Data table "Alias" ...
    "Where condition (s)"
    "Group by Group field, Group field, ..."
    "Having group after filter"
    "Order By Field" Asc|desc ", Field" Asc|desc ",......"


    From data table "alias", Data table "Alias",......,select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
    From data table "Alias", Data table "Alias" ...
    "Where condition (s)"
    "Group by Group field, Group field, ..."
    "Having group after filter"
    "ORDER By Field" Asc|desc ", Field" Asc|desc ",......";
    The Where condition (s) (select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
    From data table "Alias", Data table "Alias" ...
    "Where condition (s)"
    "Group by Group field, Group field, ..."
    "Having group after filter"
    "ORDER By Field" Asc|desc ", Field" Asc|desc ",......")】
    "Group by Group field, Group field, ..."
    "Having a group after filtering,select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
    From data table "Alias", Data table "Alias" ...
    "Where condition (s)"
    "Group by Group field, Group field, ..."
    "Having group after filter"
    "ORDER By Field" Asc|desc ", Field" Asc|desc ",......"】
    "Order By Field" Asc|desc ", Field" Asc|desc ",......"

  3. The subquery returns a single-row column: Having, where

    The subquery returns a multiple-row column: where

    Subquery returns multiple rows and columns: from

  4. Subqueries can also appear in the SELECT clause, but this is rarely done in general. At the same time, the subquery must have "()"when it appears.

  5. Use a subquery in the WHERE clause.


This article is from the "10281302" blog, please be sure to keep this source http://10291302.blog.51cto.com/10281302/1691431

Sub-query (most difficult)

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.