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

iFrame is a great way to use it as a popup layer to cover the background

I have been working on a project recently - Budou ...

The basic principles and detailed usage of viewport

1. Overview of viewport Mobile browsers usually r...

Vue implements sending emoticons in chat box

The specific code for sending emoticons in the vu...

Detailed installation and use of RocketMQ in Docker

To search for RocketMQ images, you can search on ...

MySQL 8.0.15 installation graphic tutorial and database basics

MySQL software installation and database basics a...

Detailed explanation of JavaScript data types

Table of contents 1. Literals 1.1 Numeric literal...

View the frequently used SQL statements in MySQL (detailed explanation)

#mysql -uroot -p Enter password mysql> show fu...

Vue and react in detail

Table of contents 1. Panorama II. Background 1. R...

SQL fuzzy query report: ORA-00909: invalid number of parameters solution

When using Oracle database for fuzzy query, The c...

Vue's vue.$set() method source code case detailed explanation

In the process of using Vue to develop projects, ...

A brief discussion on the lazy loading attribute pattern in JavaScript

Table of contents 1. Introduction 2. On-demand at...

JavaScript immediate execution function usage analysis

We know that in general, a function must be calle...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...