Every derived table must have its own alias - error when using multiple SELECT statements

大憨熊 提交于 2021-02-05 09:30:35

问题


I'm trying to use multiple SELECT statements in a query to get data from the database but I get an error. The query is:

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

The error is get is:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1248 Every derived table must have its own alias'

I tried changing my query to

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

but got the same error again. I can't understand which part of the query needs an alias and why


回答1:


The from table needs an alias

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

Will work

Though the query seems to make no sense. It is not a syntax error anymore



来源:https://stackoverflow.com/questions/36687035/every-derived-table-must-have-its-own-alias-error-when-using-multiple-select-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!