I'm trying to use the statement SELECT TOP 1 * FROM tasks WHERE dueDate < ?1 ORDER BY dueDate DESC
but SQLite says near "1": syntax error
. What's wrong?
Asked
Active
Viewed 6.6k times
72

ryyst
- 9,563
- 18
- 70
- 97
-
may be near this one: `dueDate < **?**1` – manji Mar 23 '11 at 13:58
-
1@najmeddine: If I delete the 1, I still get a syntax error so I don't think it's that one. I think "TOP" just might not be part of the SQLite syntax. – ryyst Mar 23 '11 at 14:00
-
6yes sqlite does not have 'TOP n' but 'LIMIT n'. My mistake just write it: `SELECT * FROM tasks WHERE dueDate < ?1 ORDER BY dueDate DESC LIMIT 1` – manji Mar 23 '11 at 14:04
1 Answers
135
Use LIMIT 1
at the end of the query instead of TOP 1
(which isn't valid sqlite syntax).
You might also need to remove the ?
in dueDate < ?1
, but I don't know sqlite well enough to be sure.

moinudin
- 134,091
- 45
- 190
- 216
-
15like as SELECT * FROM Product ORDER BY _ID DESC LIMIT 1 because the top 1 is not permitted in sqllite syntax. – Günay Gültekin Jan 06 '13 at 19:34