HTML5 数据库:DELETE LIMIT 上的 SQL 错误
我正在尝试 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于允许 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)
我不相信
delete
支持limit
(或者,至少在我所知道的任何 SQL 方言中都不支持)。相反,您要么想要通过以下方式删除表中的所有内容,要么更具体地说明要删除的行:
编辑添加:一般来说,数据库不除非您告诉它(通过 order by 语句或某些 RDBMS 中存在的 row_number() 函数),否则不会关心行的顺序。因此,一般来说,如果您多次调用
select * from my_table limit 1;
,则不能保证每次都能获得相同的行。换句话说,除非您确实只想从表中获取特定数量的行,并且不关心获得哪些行,否则如果不对通过 获取的行施加某种顺序,limit
语句很少有帮助。您的查询。I don't believe that
delete
supportslimit
(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 viaor be more specific about the rows that you want to delete:
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 arow_number()
function that is present in some RDBMSs). So, in general, if you callselect * 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, alimit
statement is rarely helpful without imposing some order on the rows fetched by your query.