Database of Neusoft Internship (7)--subquery

Source: Internet
Author: User

# #子查询

The query in parentheses is called a subquery, also called an internal query, which executes before the main query.

The result of the subquery is the main query (external query) using EXPR operator including the comparison operator.

        • Single-line operators:>, =, >=, <, <>, <=
        • Multiline operator: In, any, all

      

A subquery can be embedded in the following SQL clause:

      1. WHERE clause
      2. HAVING clause
      3. FROM clause

Sub-query usage guidance

        • Sub-query to expand with the expansion number
        • Place a subquery to the right of the comparison operator
        • The ORDER BY clause in a subquery is not required unless you are performing a top-n analysis
        • To use single-line operators for single-line subqueries
        • To use multiline operators for multiline subqueries
#子查询类型

      

#单行子查询

Single-line subquery

      • Subqueries return only one row
      • Using the single-line operator

     

      

      • Using group functions in subqueries

Check the employee's name, position and salary at the lowest wage

        

      • Using subqueries in a HAVING clause

Department number and minimum wage for the minimum wage of 20 departments

        

#多行子查询

Multiline subquery, the number of rows that a subquery returns a record can be one or more bars.

Multi-row subqueries require the use of multiline operators.

Common multiline operators include the following:

      • Inch
      • Any
      • All

The in operator is consistent with the previously described function and determines whether any one of the subquery's return values is the same. The returned result can be one or more.

#IN

      

#ANY: Indicates arbitrary.

< any is smaller than any result returned by the subquery, which is less than the maximum value of the returned result.

= any and any of the results in a subquery are equal, equivalent in.

> any is larger than any result returned by a subquery, which is greater than the minimum value of the returned result.

#ALL: Denotes all.

< All results are smaller than the subquery returns, which is less than the minimum value of the returned result.

> All results are larger than the subquery returns, which is greater than the maximum value of the returned result.

= all meaningless and logically not tenable.

      

# #多列子查询

So far you have been able to complete single-row and multiline subqueries, but only one column is compared in the WHERE or HAVING clause of the SELECT statement.

If you want to compare multiple columns, you must write a compound WHERE clause with a logical operator.

Dolez queries allow you to combine multiple conditions in a WHERE clause into a single

      

Multi-column comparison

Database of Neusoft Internship (7)--subquery

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.