How do you enable LIMIT for DELETE in SQLite?

♀尐吖头ヾ 提交于 2019-11-26 11:23:45

问题


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?


回答1:


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
cd sqlite-3.6.20
export CFLAGS='-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1'
./configure
make

Then you'll have the sqlite3 command-line utility and the library files in the .libs subdirectory.




回答2:


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
)



回答3:


DELETE FROM table WHERE rowid = (SELECT rowid FROM table WHERE condition LIMIT 1 )



回答4:


From here, it seems that you have to compile the SQLite source code using

#define SQLITE_ENABLE_UPDATE_DELETE_LIMIT

in order to enable it.



来源:https://stackoverflow.com/questions/1824490/how-do-you-enable-limit-for-delete-in-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!