MySQL "Every derived table must have its own alias" problem

Source: Internet
Author: User



My query statement



Select COUNT (*) from (SELECT * from ...) Total



Error tips



Every derived table must have its own alias



Each derived table must have an alias of its own.



This error generally occurs when you are querying multiple tables.



Because the result of a subquery coming out of a nested query is as a derived table for the query at the top level, the result of the subquery must have an alias



Change the MySQL statement to: SELECT COUNT (*) from (SELECT * from ...) as total;



The problem is solved, although only one alias total without any effect is added, but this alias is required


The code is as follows



Select Name1 name, java, JDBC, hibernate,total
From (select Sc1.name name1, Sc1.mark Java
From Student_course2 SC1
where sc1.course= ' Java ' as a,
(select Sc2.name name2, Sc2.mark JDBC
From Student_course2 SC2
where sc2.course= ' jdbc ' as B,
(select Sc3.name name3, Sc3.mark hibernate
From Student_course2 SC3
Where sc3.course= ' hibernate ') as C,
(Select Sc4.name name4,sum (Sc4.mark) Total
From Student_course2 SC4 GROUP by Sc4.name) as D
where Name1=name2 and Name2=name3 and name3=name4 order by total ASC;



The result is correct:



+----------+------+------+-----------+-------+
| name     | java | jdbc | hibernate | Total |< br> +----------+------+------+-----------+-------+
| wangwu   |   |   | & nbsp;      |    90 |
| lisi     |   |   |        50 |& nbsp;  180 |
| Zhangsan |  |   |        |   270 |
+----------+------+------+-----------+-------+
3 rows in Set (0.02 sec)


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.