HTML5 数据库:DELETE LIMIT 上的 SQL 错误

发布于 2024-12-05 01:07:09 字数 259 浏览 1 评论 0原文

我正在尝试 HTML5 数据库,发现 DELETE 不能与 LIMIT 一起使用。

在Chrome中尝试:

> select * from my_table limit 1
item  name
--------------
1     Hi

> delete from my_table limit 1
near "limit": syntax error

这个删除有什么问题吗?

谢谢。

I'm trying HTML5 database and found that DELETE is not working with LIMIT.

Trying in Chrome:

> select * from my_table limit 1
item  name
--------------
1     Hi

> delete from my_table limit 1
near "limit": syntax error

Is there any wrong with this delete?

Thanks.

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

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

发布评论

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

评论(2

下壹個目標 2024-12-12 01:07:10

对于允许 SELECT 但不允许 DELETE 的 SQL 方言,请尝试 DELETE FROM my_table WHERE item IN (SELECT item FROM my_table LIMIT 1)

For SQL dialects that allow for a LIMIT on SELECT but not DELETE, try DELETE FROM my_table WHERE item IN (SELECT item FROM my_table LIMIT 1)

把时间冻结 2024-12-12 01:07:09

我不相信 delete 支持 limit (或者,至少在我所知道的任何 SQL 方言中都不支持)。相反,您要么想要通过以下方式删除表中的所有内容

delete from my_table;

,要么更具体地说明要删除的行:

delete from my_table where item=1;

编辑添加:一般来说,数据库不除非您告诉它(通过 order by 语句或某些 RDBMS 中存在的 row_number() 函数),否则不会关心行的顺序。因此,一般来说,如果您多次调用 select * from my_table limit 1; ,则不能保证每次都能获得相同的行。换句话说,除非您确实只想从表中获取特定数量的行,并且不关心获得哪些行,否则如果不对通过 获取的行施加某种顺序,limit 语句很少有帮助。您的查询。

I don't believe that delete supports limit (or, at least it doesn't in any SQL dialect that I'm aware of). Instead, you'll either want to delete everything from the table via

delete from my_table;

or be more specific about the rows that you want to delete:

delete from my_table where item=1;

Edited to add: In general, databases don't tend to care about the order of the rows unless you tell it to (either via an order by statement or a row_number() function that is present in some RDBMSs). So, in general, if you call select * from my_table limit 1; several times, you aren't guaranteed to get the same row each time. In other words, unless you really just want a specific number of rows from a table and you don't care which rows you get, a limit statement is rarely helpful without imposing some order on the rows fetched by your query.

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