Error Code: 1248. Every derived table must have its own alias No solution found for query

送分小仙女□ 提交于 2019-12-01 17:08:45

问题


I am getting an error while using this query in MySQL.

The query logic is correct and I have tried it in Oracle and it's running fine, but I'm getting an error when running this in MySQL.

I looked at previous questions on StackOverflow, but didn't find something to help me.

Here is the query:

select * from
  (select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
    from RATOR_IMP.PROCESS_MONITOR as PM
    JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
    ON PM.ID = PMS.PROCESS_MONITOR_ID
    WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
    order by PMS.PROCESS_START_DATE desc)
limit 10000;

And here is the error:

Error Code: 1248. Every derived table must have its own alias 
No soultion found for query

回答1:


You need to provide an alias for the subquery, like so:

select * from
(select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
 from RATOR_IMP.PROCESS_MONITOR as PM
 JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
 ON PM.ID = PMS.PROCESS_MONITOR_ID
 WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
 order by PMS.PROCESS_START_DATE desc) as s
limit 10000;

From the documentation,

Subqueries are legal in a SELECT statement's FROM clause. The actual syntax is:

SELECT ... FROM (subquery) [AS] name ...

The [AS] name clause is mandatory, because every table in a FROM clause must have a name. Any columns in the subquery select list must have unique names.




回答2:


Yes you need to specify an alias for the derived data

select x.* from
(select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
from RATOR_IMP.PROCESS_MONITOR as PM
JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
ON PM.ID = PMS.PROCESS_MONITOR_ID
WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
order by PMS.PROCESS_START_DATE desc)x <-- here 
limit 10000; 


来源:https://stackoverflow.com/questions/27619026/error-code-1248-every-derived-table-must-have-its-own-alias-no-solution-found

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