Sqlserver subquery Error

Source: Internet
Author: User
Compared with oracle, if the subquery involved, the corresponding table name and field must be named with an alias before execution. There are two main scenarios: 1. in the query SQL statement, only simple subqueries do not contain grouping and summation Wait For example: elect * from (selectcom_idfromcompany). In this case, an error is reported. The outer layer must be added with an alias.

Compared with oracle, if the subquery involved, the corresponding table name and field must be named with an alias before execution. There are two main scenarios: 1. in the query SQL, only simple subqueries that do not contain grouping and summation Wait For example: elect * from (select com_id from company) will report an error. The outer layer must be added with an alias.

Compared with oracle, if the subquery involved, the corresponding table name and field must be named with an alias before execution. There are two main scenarios:

1. in the query SQL statement, only simple subqueries that do not contain grouping and summation Wait For example: elect * from (select com_id from company) will report an error. An alias must be added to the outer layer ,, select * from company in the lower layer can be added with an alias or incorrect: select * from (select com_id from company)

2. when the queried SQL contains grouping, summation, and other functions, for example: select * from (select com_id, count (com_id) from company group by com_id) a: If an alias is added to the outermost SQL, an error is returned. The alias B select * from (select com_id, count (com_id) from company B group by com_id) is added to company) a does not work either. In fact, the count () function can also be used as a subquery. Therefore, you must add an alias to count (): select * from (select com_id, count (com_id) c from company B group by com_id)

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.