【mysql报错】[Err] 1248 - Every derived table must have its own alias

当我运行一条联合查询的sql语句时报以下错误:

[Err] 1248 - Every derived table must have its own alias,大概意思是每一张派生表必需要有本身的别名。这里加上别名便可。sql

原先sql:spa

 

select * from t_test t1 where t1.content like '%test%'
Union all
select * from (select * from t_test t2 where t2.content not like '%test%' order by t2.content asc);

 

加上别名以后:code

select * from t_test t1 where t1.content like '%test%'
Union all
select * from (select * from t_test t2 where t2.content not like '%test%' order by t2.content asc) d;

再运行一遍以后问题解决blog