When mysql executes a multi-table query, an error occurs:
Sql code Collection code
[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
What this means is that each derived table must have its own alias
This error generally occurs when multi-table queries or sub-queries are used, because in nested queries, the result of the sub-query is used as a derived table to query the upper level, so the result of the sub-query 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 the sentence as total after the subquery is equivalent to aliasing the result set derived table of the subquery as total, and the problem is solved.