我可以在一个SQL语句中删除2个表中的行吗?

时间:2021-04-30 15:24:22

I have 2 tables one called "REVIEW" and the other "REVIEW_DESCRIPTION"

我有2个表,一个叫“REVIEW”,另一个叫“REVIEW_DESCRIPTION”

If I do a join to get all the data from both:

如果我进行连接以获取两者的所有数据:

SELECT *
FROM reviews 
INNER JOIN reviews_description
ON reviews.reviews_id=reviews_description.reviews_id
WHERE reviews.customers_id = 54183

Based on this I would like to delete rows in both tables that match this criteria in one shot, any tips?

基于此,我想删除两个表中符合此条件的行,一次性提示,任何提示?

3 个解决方案

#1


3  

Yes, MySQL supports deletions from more than one table in a single statement:

是的,MySQL支持在单个语句中删除多个表:

For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted. For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted. The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching...

对于第一个多表语法,仅删除FROM子句之前列出的表中的匹配行。对于第二个多表语法,仅删除FROM子句(USING子句之前)中列出的表中的匹配行。结果是您可以同时从多个表中删除行,并具有仅用于搜索的其他表...

First multi-table syntax example:

第一个多表语法示例:

DELETE reviews, reviews_description 
  FROM reviews r
  JOIN reviews_description rd
 WHERE reviews.reviews_id = reviews_description.reviews_id
   AND reviews.customers_id = 54183

#2


1  

Unless you have on cascade delete or a delete trigger setup you need to use 2 statements

除非您有级联删除或删除触发器设置,否则您需要使用2个语句

#3


0  

would cascade delete help?

会级联删除帮助吗?

#1


3  

Yes, MySQL supports deletions from more than one table in a single statement:

是的,MySQL支持在单个语句中删除多个表:

For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted. For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted. The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching...

对于第一个多表语法,仅删除FROM子句之前列出的表中的匹配行。对于第二个多表语法,仅删除FROM子句(USING子句之前)中列出的表中的匹配行。结果是您可以同时从多个表中删除行,并具有仅用于搜索的其他表...

First multi-table syntax example:

第一个多表语法示例:

DELETE reviews, reviews_description 
  FROM reviews r
  JOIN reviews_description rd
 WHERE reviews.reviews_id = reviews_description.reviews_id
   AND reviews.customers_id = 54183

#2


1  

Unless you have on cascade delete or a delete trigger setup you need to use 2 statements

除非您有级联删除或删除触发器设置,否则您需要使用2个语句

#3


0  

would cascade delete help?

会级联删除帮助吗?