Select TOP 1 * from Table Fails in Sybase Procedure

大兔子大兔子 提交于 2019-12-23 12:33:40

问题


Am trying to Fetch Only one record from the Sybase Table without using the RowCount Function, even though "WHERE Condition" returns multiple results.

SELECT TOP 1 EMPLOYEE_NAME FROM EMPLOYEES WHERE EMPLOYEEID > 50

Runs Successfully with one Record Only,

However

SELECT TOP 1 EMPLOYEE_NAME FROM EMPLOYEES WHERE EMPLOYEEID > 50

fails, when written inside a Sybase Procedure as a Sub Query


回答1:


Top is supported only in outer query only, here is the link

For ordered data I am using having cause instead Top 1 in Sybase, like:

SELECT  EMPLOYEE_NAME FROM EMPLOYEES WHERE EMPLOYEEID > 50 HAVING EMPLOYEEID = MIN(EMPLOYEEID)

I hope it helps a bit. GL!




回答2:


I know it is late but just for others TOP inside a subquery can be used in sybase latest version.



来源:https://stackoverflow.com/questions/15449565/select-top-1-from-table-fails-in-sybase-procedure

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