Solution to the MySQL error "Every derived table must have its own alias"

Solution to the MySQL error "Every derived table must have its own alias"

MySQL reports an error when executing multi-table query:

[SQL] SELECT * from 
(
select e.account from employee e
UNION
SELECT u.account from `user` u
UNION
SELECT a.account from agent a
)
[Err] 1248 - Every derived table must have its own alias

This means that each derived table must have its own alias.

This error usually occurs when querying multiple tables or subqueries. In a nested query, the result of the subquery is used as a derived table for querying the upper level, so the result of the subquery must have an alias.

In the above example, modify the query statement:

SELECT * from 
(
select e.account from employee e
UNION
SELECT u.account from `user` u
UNION
SELECT a.account from agent a
)as total

As shown above, adding a sentence as total after the subquery is equivalent to giving the derived table of the subquery result set an alias of total, and the problem is solved.

You may also be interested in:
  • Steps for installing MySQL 8.0.16 on Windows and solutions to errors
  • Solution to MySQL error code 1862 your password has expired
  • How to solve mysql error 10061
  • MySql inserts data successfully but reports [Err] 1055 error solution
  • How to solve the abnormal error ERROR: 2002 in mysql
  • Solution to 1045 error when navicat connects to mysql
  • How to solve the error 1093-You can't specify target table for update in FROM clause in MySQL

<<:  js date and time formatting method example

>>:  Solve the problem of Linux FTP anonymous upload and download starting automatically

Recommend

How to query the minimum available id value in the Mysql table

Today, when I was looking at the laboratory proje...

Application of Beautiful Style Sheets in XHTML+CSS Web Page Creation

This is an article written a long time ago. Now it...

How to install phabricator using Docker

I am using the Ubuntu 16.04 system here. Installa...

The process of installing Docker in Linux system

In this blog, I will walk you through the process...

Solution to the problem of large font size on iPhone devices in wap pages

If you don't want to use javascript control, t...

Vue detailed explanation of mixins usage

Table of contents Preface 1. What are Mixins? 2. ...

Why does your height:100% not work?

Why doesn't your height:100% work? This knowl...

Detailed process of installing various software in Docker under Windows

1. Install MySQL # Download mysql in docker docke...

Beginners learn some HTML tags (2)

Beginners can learn HTML by understanding some HT...

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...

Introducing the code checking tool stylelint to share practical experience

Table of contents Preface text 1. Install styleli...

What is the use of the enctype field when uploading files?

The enctype attribute of the FORM element specifie...