删除mysql第n行
我正在使用 MySQL v5.0.45 并尝试删除表中的第 n 行,无论其 ID 号如何。我在 PHP 中设置了一个原型,然后将其集成到我的 Web 开发项目中,在数据库中设置了以下内容:
CREATE TABLE prototype_1 (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name varchar(30));
INSERT INTO prototype_1 (name) VALUES ('A');
INSERT INTO prototype_1 (name) VALUES ('B');
INSERT INTO prototype_1 (name) VALUES ('C');
足够简单!现在我尝试使用“LIMIT”,但收到以下错误:
“ERROR 1235 (42000): This version of MySQL does not support 'LIMIT & IN/ALL/ANY/SOME subquery'”
现在我明白你不能使用然而,子查询中的 LIMIT 是否没有某种解决方法?
我可以选择第 n 行并通过以下内容很好地显示它:
SELECT * FROM prototype_1 LIMIT 1,1;
因此返回 'B' 但为什么我不能删除!?
I'm using MySQL v5.0.45 and trying to delete the nth row in a table irrespective of its ID number. I set up a prototype in PHP before integrating it into my web development project where I set up the following in my database:
CREATE TABLE prototype_1 (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name varchar(30));
INSERT INTO prototype_1 (name) VALUES ('A');
INSERT INTO prototype_1 (name) VALUES ('B');
INSERT INTO prototype_1 (name) VALUES ('C');
Simple enough! Now I tried using 'LIMIT' but I get the following error:
"ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
Now I understand you cannot use LIMIT in subqueries, however, is there not some sort of work around?
I can select the nth row and display it nicely with the following:
SELECT * FROM prototype_1 LIMIT 1,1;
Thus returning 'B' but why cannot I delete!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要一个像这样的小技巧
来自 docs
You need a little trick like this
From docs
像这样删除第 n 条记录。确保按所需的列对结果进行排序,在本例中为
id
列:Delete the
n
-th record like this. Make sure you order the result by the column you want, in this case theid
column: