MySQL LIMIT on DELETE语句 [英] MySQL LIMIT on DELETE statement

查看:146
本文介绍了MySQL LIMIT on DELETE语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整理了一张测试表,查找我最近遇到的错误.尝试从MySQL表中删除单个记录时,它涉及使用LIMIT.

I put together a test table for a error I recently came across. It involves the use of LIMIT when attempting to delete a single record from a MySQL table.

我所说的错误是"您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取在第1行的'LIMIT 1'附近使用的正确语法 "

我放在一起的桌子叫做 test ;它有3列,分别是 id name created .我用几条记录填充了表,然后尝试删除一条.下面是我用来尝试完成此操作的语句.

The table I put together is called test; it has 3 columns, id, name and created. I populated the table with several records and then attempted to delete one. Below is the statement I used to try and accomplish this.

DELETE t FROM test t WHERE t.name = 'foo' LIMIT 1

不使用LIMIT 1,该语句执行得很好,但是如果不需要它,我当然不会使用LIMIT.

Without the use of LIMIT 1, the statement executes just fine, but of course I wouldn't be using LIMIT if there wasn't a need for it.

我完全知道我可以使用另一条语句成功完成此DELETE.见下文: DELETE FROM test WHERE name = 'foo' LIMIT 1

I'm fully aware that I can use another statement to accomplish this DELETE successfully. See below: DELETE FROM test WHERE name = 'foo' LIMIT 1

但是我的问题集中在为什么第一条语句不能与LIMIT一起使用.

However my question is centered on why the first statement isn't working with LIMIT.

所以我的问题是,关于生成此错误的第一条语句,我做错了什么?

So my question is, what I have done incorrectly with respect to the first statement to generate this error?

推荐答案

删除查询仅允许在DELETE命令"后告诉数据库什么/如何处理内容的修饰符.

the delete query only allows for modifiers after the DELETE 'command' to tell the database what/how do handle things.

请参见此页面

这篇关于MySQL LIMIT on DELETE语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆