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?
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.
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).
DELETE FROM table WHERE rowid = (SELECT rowid FROM table WHERE condition LIMIT 1 )
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With