Home > Database > Mysql Tutorial > body text

Mysql异常:Every derived table must have its own alias

WBOY
Release: 2016-06-07 16:25:11
Original
1223 people have browsed it

Mysql错误:Every derived table must have its own alias mysql执行多表查询时报错: [SQL] SELECT * from (select e.account from employee eUNIONSELECT u.account from `user` uUNIONSELECT a.account from agent a)[Err] 1248 - Every derived table mus

Mysql错误:Every derived table must have its own alias

mysql执行多表查询时报错:

[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
Copy after login

这句话的意思是每个派生出来的表必须有一个自己的别名

?

一般是在多表查询或者子查询的时候会出现这个错误,因为在嵌套查询中,子查询的结果是作为一个派生表给上一级进行查询,所以子查询的结果必须有一个别名。

?

上面的例子中,把查询语句修改一下:

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

如上所示,在子查询的后面增加一句 as total,相当于给子查询的结果集派生表取别名为total,问题就解决了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!