Fundamentals of database Development-Lesson Plans-6 sub-queries

Source: Internet
Author: User

Sub-query, also called nested query.

A query statement is used as a result set for other SQL statements, just as a query statement that is treated as a result set is called a subquery, as with a normal table.

There are two types of sub-queries:

One is to return only a single-valued subquery, at which point it can be used where a single value can be used, when a subquery can be considered a function that has a return value;

Another is a subquery that returns a column of values, at which point the subquery can be thought of as a data table that is temporarily present in memory.

Create a new department table, an employee table, and a department column number for each person in the employee table.

Sub-query Example:

Practice One:

Exercise two:

Exercise Three:

Example of a paged query statement:

See how many pages can be divided into a total:

Practice:

Subquery Practice One: Find out All information about people who are older than seven years old in the sales department

Exercise two: convert all numeric codes from a department in a haha table to a string display in a bumen table

Exercise three: Convert all the number codes from the department in the haha table to The string display in the Bumen table, and show each person's supervisor

Fundamentals of database Development-Lesson Plans-6 sub-queries

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.