0

in MySQL I am able to use LIMIT clause but not in the sybase. I have found a lot of question and answers on the net but I can't find what I want. I have tried this

    SELECT TOP 5 * FROM Employees ORDER BY Surname;

but sybase throws and error.it says incorrect syntax near 5. I have also tried this one

SELECT BOTTOM 5 * FROM
(SELECT TOP 15 * FROM someTable
ORDER BYorderColumns DESC)

also not working. and also this one:

SET ROWCOUNT 60
DECLARE @name VARCHAR
SELECT @name = name
FROM user
WHERE something = $something
ORDER BY date ASC

SET ROWCOUNT 20
SELECT *
FROM user
WHERE name >= @name

this is not working since I don't have any ID number in the table, but only name which has varchar data type. Any ideas guys? Thank you so much in advance.

Charles
  • 50,943
  • 13
  • 104
  • 142
Bizarre
  • 106
  • 2
  • 12

1 Answers1

0

I'm not sure which sybase do you use, but this:

SELECT TOP 5 * FROM Employees ORDER BY Surname

will work on ASE.

You can also try this way:

SELECT TOP(5) * FROM Employees ORDER BY Surname;
Robert
  • 25,425
  • 8
  • 67
  • 81
  • I am using Sybase v15. TOP is now working, no problem, but once i put bottom, i got syntax error. – Bizarre Dec 14 '12 at 10:02
  • @Bizarre `bottom` is not valid on sybase ase. With this information I can't help you now. Show us your example data, and what result do you expect. – Robert Dec 14 '12 at 10:07
  • since bottom is not working, I have changed the way i'm displaying it.I am using LIMIT in MySQL to do a pagination, so i would like to achieve same task with sybase. but since it cannot be done, I have retrieve all records from database, and sort them using PHP stuffs... – Bizarre Dec 21 '12 at 04:11