[英]SQL: Deleting rows from table based on columns selected from another table
I'm trying to select rows in a table identified by the values in two columns. 我正在尝试选择由两列中的值标识的表中的行。 The values are found in another table. 这些值在另一个表中找到。 An example should help: 一个例子应该有帮助:
Table1 表格1
A | B | C
101 1 x
102 1 o
103 1 o
SELECT A, B FROM Table1 where Table1.C = 'o'
Returns: 返回:
A | B
102 1
103 1
I want to delete rows in Table2 where A and B match those returned by the query on Table1. 我想删除Table2中的行,其中A和B与Table1的查询返回的行匹配。
Table2 表2
A | B | D
101 1 Not deleted
102 1 Deleted
103 1 Deleted
Becomes: 变为:
A | B | D
101 1 Not selected
The first select works, but I can't see where to go from there. 第一次选择有效,但我看不到要去哪里。 I currently have the following, but it's throwing an error and I'm not clear what I should be doing. 我目前有以下内容,但它引发了错误,并且我不清楚我应该做什么。 Tutorials welcome as I'm new to SQL. 欢迎使用教程,因为我是SQL新手。
DELETE Table2
where A, B in
(SELECT A, B FROM Table1
where Table1.C = 'o')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.