Sqlite如何删除表的最后添加条目

发布于 2024-09-30 14:21:32 字数 225 浏览 0 评论 0原文

我正在尝试删除表中最后添加的条目:

DELETE FROM notes ORDER BY created_at DESC LIMIT 1

这只会导致以下错误:

near "ORDER": syntax error

为什么我会收到此错误? (notes 存在并且其中有记录!)

I'm trying to delete the last added entry of a table:

DELETE FROM notes ORDER BY created_at DESC LIMIT 1

This just causes the following error:

near "ORDER": syntax error

Why might I be getting this error? (notes exists and has records in it!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飞烟轻若梦 2024-10-07 14:21:32

试试这个

DELETE FROM notes WHERE id = (SELECT MAX(id) FROM notes);

Try this

DELETE FROM notes WHERE id = (SELECT MAX(id) FROM notes);
初见 2024-10-07 14:21:32
delete from notes where created_at = ( select max(created_at) from notes );

请注意,这不会限制删除的行数。如果 max(created_at) 处有多于一行,这将删除所有行,因为您指定的主题不存在(表的最后添加条目)。

delete from notes where created_at = ( select max(created_at) from notes );

Watch out, this will not limit the number of rows deleted. If there are more than one row at max(created_at), this will delete all of them because the subject you specified does not exist (last added entry of a table).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文