A
A
Alexander Karadiaur2021-10-07 11:52:23
SQLite
Alexander Karadiaur, 2021-10-07 11:52:23

LIMIT and ORDER not working, how to fix?

I enter these commands

BEGIN TRANSACTION;

/* Create a table called NAMES */
CREATE TABLE NAMES(Id integer, Name text);

/* Create few records in this table */
INSERT INTO NAMES VALUES(1,'Tom');
INSERT INTO NAMES VALUES(2,'Lucy');
INSERT INTO NAMES VALUES(3,'Frank');
INSERT INTO NAMES VALUES(4,'Jane');
INSERT INTO NAMES VALUES(4,'HellO!');
INSERT INTO NAMES VALUES(5,'Robert');
COMMIT;

DELETE FROM NAMES WHERE Id = 4 LIMIT 1;

SELECT * FROM NAMES;


I get this:
1|Tom
2|Lucy
3|Frank
4|Jane
4|HellO!
5|Robert
Error: near line 15: near "LIMIT": syntax error


How to fix error with LIMIT? (exactly the same error if I try to do something with ORDER BY)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2021-10-07
@twiwter

subqueries

DELETE FROM Foo
WHERE someColumn in
(
  SELECT someColumn FROM FOO WHERE SomeCondition LIMIT 4
)

I
idShura, 2021-10-07
@idShura

In sqlite, you need to enable delete limit, google SQLITE_ENABLE_UPDATE_DELETE_LIMIT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question