每个派生表必须有自己的别名 - 使用多个SELECT语句时出错

时间:2016-04-18 06:42:20

标签: mysql select

我正在尝试在查询中使用多个SELECT语句从数据库中获取数据,但是我收到错误。查询是:

SELECT * 
        FROM (SELECT * 
              FROM players 
              WHERE lid = 0)
        WHERE NOT EXISTS (SELECT * 
                          FROM players 
                          WHERE lid = 1)

错误是获取:

  

致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1248每个派生表必须具有自己的别名'

我尝试将查询更改为

SELECT * 
        FROM (SELECT * 
              FROM players 
              WHERE lid = 0)
        WHERE NOT EXISTS (SELECT * 
                          FROM players 
                          WHERE lid = 1) AS T

但又一次犯了同样的错误。我无法理解查询的哪个部分需要别名以及为什么

1 个答案:

答案 0 :(得分:0)

from table需要一个别名

SELECT * 
        FROM (SELECT * 
              FROM players 
              WHERE lid = 0) as T
        WHERE NOT EXISTS (SELECT * 
                          FROM players 
                          WHERE lid = 1)

会工作

虽然查询似乎毫无意义。它不再是语法错误