如何将此MySQL SELECT查询转换为DELETE查询? [英] How to turn this MySQL SELECT query into a DELETE query?
问题描述
我想从数据库中删除某些项目.我有以下查询:
I want to delete certain items from the database. I have the following query:
SELECT *
FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
这有效,并返回2个结果.
This works, and returns 2 results.
现在,我想将此SELECT
查询转换为DELETE
查询.但是,以下操作无效:
Now I want to turn this SELECT
query into a DELETE
query. However, the following doesn't work:
DELETE FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
MySQL引发以下错误:
MySQL throws the following error:
1064-您的SQL语法有错误;检查手册 对应于您的MySQL服务器 使用正确语法的版本 在'WHERE entry.sheetID =附近 sheets.id和sheets.clientID = 13',位于 第1行
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE entries.sheetID = sheets.id AND sheets.clientID = 13' at line 1
我在做什么错了?
推荐答案
MySQL 4及更高版本支持使用以下语法一次从多个表中删除:
MySQL 4 and up supports deleting from multiple tables at once, using the following syntax:
DELETE sheets, entries
FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
如果您使用的是低于版本4的MySQL,则需要一次从一个表中删除行,并且可以使用此处发布的其他解决方案之一.
If you're using MySQL below version 4, then you need to delete rows from one table at a time, and you can use one of the other solutions posted here.
这篇关于如何将此MySQL SELECT查询转换为DELETE查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!