MySQL encounters an error similar to "Everyderivedtablemusthaveitsownalias"

Source: Internet
Author: User
MySQL encounters ldquo; Everyderivedtablemusthaveitsownaliasrdquo; similar error description

MySQL encounters ldquo; Every derived table must have its own aliasrdquo; similar error description

Every derived table must have its own alias

This statement means that each derived table must have its own Alias.

This error occurs when multiple tables are queried.

Because, when performing nested queries, the results of the subquery are used as a derived table to perform the query at the upper level. Therefore, the subquery results 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" is added, this alias is required.

Select name1 name, java, jdbc, hibernate, total
From (select sc1.name name1, sc1.mark java
From student_course2 sc1
Where sc1.course = 'java') as,
(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 |
+ ---------- + ------ + ----------- + ------- +
| Wangwu | 40 | 30 | 20 | 90 |
| Lisi | 70 | 60 | 50 | 180 |
| Zhangsan | 100 | 90 | 80 | 270 |
+ ---------- + ------ + ----------- + ------- +
3 rows in set (0.02 sec)

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

MySQL-5.5.38 universal binary Installation

-------------------------------------- Split line --------------------------------------

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.