Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable LIMIT for DELETE in SQLite?

Using PHP, I have a simple database that may store multiple items with the same content. I want to delete the first occurrence of an instance when I use DELETE.

How do you enable LIMIT for DELETE in SQLite using PHP?

like image 388
user5243421 Avatar asked Dec 01 '09 07:12

user5243421


People also ask

How do I limit rows in SQLite?

SQLite Limit: You can limit the number of rows returned by your SQL query, by using the LIMIT clause. For example, LIMIT 10 will give you only 10 rows and ignore all the other rows. In the LIMIT clause, you can select a specific number of rows starting from a specific position using the OFFSET clause.

Does SQLite have a limit?

When used with the maximum page size of 65536, this gives a maximum SQLite database size of about 281 terabytes. The max_page_count PRAGMA can be used to raise or lower this limit at run-time. The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19).


2 Answers

DELETE FROM table WHERE rowid = (SELECT rowid FROM table WHERE condition LIMIT 1 )
like image 74
Chakalaka Avatar answered Sep 17 '22 13:09

Chakalaka


You can use limit with select and you can combine select and delete like:

DELETE FROM Foo
WHERE someColumn in
(
  SELECT someColumn FROM FOO WHERE SomeCondition LIMIT 200
)
like image 34
Andreas Avatar answered Sep 17 '22 13:09

Andreas