从多个字段匹配的表中删除从其他表中选择子查询结果

时间:2017-03-08 06:35:35

标签: sql oracle

我想删除表中的一个条目,其中多个字段与从另一个表中获取数据的另一个select子查询的结果匹配。

查询:

DELETE FROM table1
WHERE carriedby_circuit IN (SELECT
    circuit_id
FROM table2
WHERE circuit_name IN (SELECT
    t.sc_prod_service_id
FROM table3 t));

所以我想修改查询,以便circuit_id table2carriedBY_circuit CARRIED_CIRCUITtable1table1形成this.subscription = activatedRoute.params.subscribe( (param: any) => { this.artType = param['artPage']; this.artWork = this.artService.getData() .subscribe( (data) => this.artWork = data ); }); 。它应该从struct Tuple { int crossSum; int crossLow; int crossHigh; }; struct Tuple findmaxcrossingsubarray(int A[], int low, int mid, int high){ int leftSum = -INFINITY; int sum = 0; int i; int j; int *crossLow; int *crossHigh; int *crossSum; for ( j = mid; j == low; j--) { sum = sum + A[j]; if (sum > leftSum) leftSum = sum; crossLow = &j; //THIS COULD BE WRONG } int rightSum = -INFINITY; sum = 0; for (i = mid + 1; i == high ; i++) { sum = sum + A[j]; if (sum > rightSum) rightSum = sum; crossHigh= &i; } crossSum = crossLow + crossHigh; } void foo() { struct Tuple t = findmaxcrossingsubarray(); } 删除行。

2 个答案:

答案 0 :(得分:0)

您可以尝试merge

merge into table1 t1
  using (select t2.circuit_id from table2 t2 inner join table3 t3 on t2.circuit_name = t3.sc_prod_service_id) d
  on (d.circuit_id = t1.carriedby_circuit or d.circuit_id = t1.carried_circuit)
when matched then delete;

答案 1 :(得分:0)

假设您有3个表,并且您正在使用ID。表1,表2和表3。您最好的方法是将table2与table3连接。然后查询其结果,从table1中删除。 例如:

DELETE FROM table1
WHERE table1.id IN(SELECT distinct id FROM tabel1 UNION SELECT ID as id    FROM tabel2);

PS:联盟选择可能会复制你的ID,这就是为什么我建议使用distinct。