内部连接和删除在 mysql 中不起作用 [英] Inner join and delete not working in mysql

查看:39
本文介绍了内部连接和删除在 mysql 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表 table1table2.我想根据 table2 中的条件从 table1 中删除.

I have two tables table1 and table2. I want to delete from table1 based on a condition in table2.

我有以下 mysql 查询:

I have the following mysql query:

DELETE FROM table1 
INNER JOIN table2 ON table2.col1 = table1.col1
WHERE table2.col2 = '1'

这会返回一个语法错误.上面的语法有问题吗?

This return a syntax error. Is there something wrong with the above syntax?

推荐答案

您需要指定要从中删除的表:

You need to specify the table you are deleting from:

DELETE table1
    FROM table1 INNER JOIN
         table2
         USING (col1) 
    WHERE table2.col2 = '1';

这篇关于内部连接和删除在 mysql 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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