简体   繁体   中英

MySQL syntax error near “from (subquery) 'table'”

select *
from ( select * from table ) 'table1';

I cannot see why I am getting this error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''table1'' at line 2 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''table1'' at line 2

I have checked the manual ( MySQL subquery in FROM clause ) and I can't see any difference between the examples and my little statement.

Table names/aliases must either be surrounded with backticks or nothing

select *
from ( select * from table1 ) table1;

I think you want back quotes rather than forward quotes:

select *
from ( select * from table ) `table1`;

Forward quotes specify a string constant. Back quotes delimit a name.

当您有一个子查询是一个表时,您需要使用一个名称声明它。

select * from (select * from table1) as x

除了不在别名周围添加引号之外,我相信你还需要在子查询中围绕“table”进行反引号,因为它是MySQL中的保留字(假设你确实将表命名为“table”):

select * from ( select * from `table` ) table1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM