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

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

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

原先sql:

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);

加上别名之后:

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;

再运行一遍之后问题解决

猜你喜欢

转载自www.cnblogs.com/HeiDi-BoKe/p/11763494.html