4

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

Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
user2104391
  • 413
  • 4
  • 9
  • 18

2 Answers2

7

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!

www
  • 4,365
  • 1
  • 23
  • 24
-2

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

Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71