TOP and ORDER BY sql error
you have an invalid sql syntax. use LIMIT instead
try this:
SELECT id
FROM table
ORDER BY id DESC
LIMIT 1
the TOP
clause works on MSSQL server.
A simpler and more DBMS-agnostic approach would be:
SELECT MAX(id) AS id
FROM table
That's only if you want just the id
field, otherwise if you tried to SELECT other columns, it wouldn't return matching data to the id
field and you would instead have to use:
SELECT id, otherfields, ..., ...
FROM table
WHERE id = (SELECT MAX(id) FROM table)