Not registered yet?
Register now! It is easy and done in 1 minute and gives you access to special discounts and much more!
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?
DELETE FROM table WHERE rowid = (SELECT rowid FROM table WHERE condition LIMIT 1 )
Or: DELETE FROM table WHERE rowid IN (SELECT rowid FROM table WHERE condition LIMIT amount_of_rows)
Worked for me. Thank you
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
Clever trick. One more thing: it is safer to use PK column for someColumn.
You cannot enable these options from within PHP, you need to compile SQLite yourself in order to enable these options. Importantly, you need to download the full version, not the amalgamation source release from SQLite download page.
If you're on Unix, get the sqlite-3.6.20.tar.gz tarball and download it. Then:
tar xzf sqlite-3.6.20.tar.gz
Then you'll have the sqlite3 command-line utility and the library files in the .libs subdirectory.
I know you didn't do this, but why was my question locked?
I found it didn't work, the version I use is 184.108.40.206. Any other ideas?
From here, it seems that you have to compile the SQLite source code using
in order to enable it.
Whoops, I should have noted that I'm doing this with php.