在MySql和SQL Server中使用子查询时,必须给子查询语言取一个别名。
例如直接使用:
select count(*) from (select * from table_1)
会提示错误,在MySql中提示错误:
Every derived table must have its own alias
在SQL Server中提示错误:
Incorrect syntax near ')'.
正确的用法应该是
select count(*) from (select * from table_1) table_2
别名是必须的,即使外层查询没有用到,也必须给子查询起一个别名,否则无法执行