I'm using PHP to connect to a MS Sql database. I've got it all working except I can't seem to get the LIMIT to work.
The following query returns an error:
$query = "SELECT name, id, startDate FROM events LIMIT 0, 20";
Here's the Error it's returning:
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '0'. (severity 15) in /var/www/vhosts/[hidden]/index.php on line 201
I've also tried using the following:
$query = "SELECT name, id, startDate FROM events LIMIT 20";
But it returns the same result.
Now, the same query without the "limit" in it, returns fine... but loads over 6,000 results which I obviously don't want :)
Anyone have any ideas? Troy
LIMIT is MySQL syntax -- on SQL Server, you need to use TOP :
SELECT TOP 20
e.name,
e.id,
e.startDate
FROM EVENTS e
Unlike LIMIT, TOP doesn't have the ability to specify an offset in case you're looking to use this for pagination.
It looks like you are using MySQL syntax on a SQL Server. SQL Server doesn't have the LIMIT option. You can try the TOP command in SQL Server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.