今天在学习内联视图子查询时遇到了一个没见过的错误:
Every derived table must have its own alias
百度翻译:每个派生表都必须有自己的别名
原sql语句:
select * from (select * from teachers_bkp where country = 'USA') where age = (select max(age) from teachers_bkp);
错误产生的原因是(select * from teachers_bkp where country = ‘USA’) 这个子句。该语句会生成一张新表,但是mysql又要求每个派生表都必须有自己的别名,所以给新表加上表名就可以了。
修改后sql:
select * from (select * from teachers_bkp where country = 'USA') new_table where age = (select max(age) from teachers_bkp);