MySQL from sub-query

Source: Internet
Author: User
Sub-query in FROM clause

The MySQL from subquery refers to the FROM clause as a subquery statement, and the main query then obtains the required data in the subquery results. The FROM subquery syntax is as follows:

SELECT ... From (subquery) as name ...

A subquery generates a temporary table, because each table in the FROM clause must have a name, so as name is required. The from subquery is also known as a derived data table subquery.

From child query instance
Table1:
S1 S2
1 5
2 12
3 20

The From subquery SQL is as follows:

Select S1,s2 from (select S1, s2*2 as S2 from table1) as temp WHERE S1 > 1

The results of the query return are as follows:

S1 S2
2 24
3 40
Tips

A subquery in the MySQL FROM clause can return a scalar, column, row, or table, but not a subquery that has an associated query.

MySQL from sub-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.