Error Code: 1248. Every derived table must have its own alias

あるテーブルに対して以下のようなSQLを発行する。

select ( case when (select * from (select * , count(*) as count from SAMPLE where columnA = 1 group by columnB) where count >= 5) then ( select * from SAMPLE where columnC = 1 and columnD = 0 and columnE = 0 ) else null end)

このSQLのままだと

Every derived table must have its own alias

というエラーが出る。

「derived」は生成された、という意味。

意訳(ほぼ直訳だけど)すると、すべての生成されたテーブルはそれぞれのエイリアスを持たなければならない、とのこと。

派生テーブルにはエイリアスをつけてあげろよな!ということなので、

select ( case when (select * from (select * , count(*) as count from SAMPLE where columnA = 1 group by columnB) as SAMPLE_A where count >= 5) then ( select * from SAMPLE_A where columnC = 1 and columnD = 0 and columnE = 0 ) else null end)

にしてあげるとこのエラー自体はなくなりました。