MySQL
SQL

MySQL — Error When Subquery Is Not AS | Every derived table must have its own alias


problem

For example, if you write a subquery like this, you get angry.

 SELECT * FROM ( SELECT User from user ); 

=> ERROR 1248 (42000): Every derived table must have its own alias


Solution

Give some table name (alias name) in AS.

 SELECT * FROM ( SELECT User from user ) AS account; 

+-----------+ | User | +-----------+ | mysql.sys | | root | +-----------+


the reason

If you do not write AS, SQL is interpreted syntactically like "FROM (without table name)".


environment


  • mysql Ver 14.14 Distrib 5.7.12, for osx 10.11 (x86_64) using EditLine wrapper


Original by

MySQL — サブクエリに AS を付けないとエラーを起こす | Every derived table must have its own alias


About

About this translattion