使用子查询删除SQL [英] SQL Delete with Subquery

查看:105
本文介绍了使用子查询删除SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用子查询的结果从表中删除.结果返回一个唯一的元组,当前我最终删除的不仅仅是返回的结果,因为我只检查col1结果.

I'm trying to delete from a table with the results of a subquery. The results return a unique tuple, and currently I end up deleting more than just the results returned because i'm only checking col1 results.

DELETE FROM Table1 exTable
WHERE exTable.col1 = ... AND exTable.col2 = ...
(SELECT col1, col2
FROM ...)

推荐答案

使用join匹配多于1列.

DELETE t1
FROM Table1 t1
inner join 
(
   select col1, col2 
   from other_table 
   where ...
) t2 on  t2.col1 = t1.col1 
     and t2.col2 = t1.col2

这篇关于使用子查询删除SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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