mysql-subquery, derived table, generic expression

Source: Internet
Author: User

mysql-Sub-query

A MySQL subquery is a query that is nested within another query.

MySQL subqueries can also be nested within another subquery.

A MySQL subquery is called an internal query, and a query that contains subqueries is called an external query.

The query returns employees who work in an office in the United States (USA). Select     lastName, Firstnamefrom    employeeswhere    officecode in (select             officecode            from Offices        WHERE            'USA');

mysql-derived type

Derived and subqueries are often used interchangeably. When SELECT FROM you use a standalone subquery in a clause in a statement, we call it a derived table

subqueries, derived tables must have aliases so that their names can be referenced later in the query.

Instance:

The Orders table and the OrderDetails table were awarded the top 5 products with the highest sales revenue in 2013: SELECT     productCode,     * priceeach)) Salesfrom    OrderDetails        INNER JOIN    orders USING (ordernumber) WHERE    =5;

mysql-Common expression (CTE)

A common table expression is a named temporary result set that exists only within the execution scope of a single SQL statement.

Query Customer information: with Customers_in_usa as (    SELECT         customerName, state    from        customers    WHERE         'USA') SELECT     customerName from    customers_in_usa WHERE     ' CA ' ORDER by CustomerName;

mysql-subquery, derived table, generic expression

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.