首页 > 代码库 > Mysql碰到“Every derived table must have its own alias”类似错误说明
Mysql碰到“Every derived table must have its own alias”类似错误说明
Every derived table must have its own alias
这句话的意思是说每个派生出来的表都必须有一个自己的别名
一般在多表查询时,会出现此错误。
因为,进行嵌套查询的时候子查询出来的的结果是作为一个派生表来进行上一级的查询的,所以子查询的结果必须要有一个别名
把MySQL语句改成:select count(*) from (select * from ……) as total;
问题就解决了,虽然只加了一个没有任何作用的别名total,但这个别名是必须的
select name1 name, java, jdbc, hibernate,total
结果正确:
+----------+------+------+-----------+-------+
| name
+----------+------+------+-----------+-------+
| wangwu
| lisi
| zhangsan |
+----------+------+------+-----------+-------+
3 rows in set (0.02 sec)
Mysql碰到“Every derived table must have its own alias”类似错误说明