ERROR ::QUERY FAILING in DELETE STATEMENT
I have a requirement that I want rows selected based on a condition from table A and table B must be deleted.
For example EMP and EMP1 are two tables
Merge into emp1 a
using (select * from emp) b
on (a. empno =b.empno)
WHEN MATCHED THEN DELETE
where(b.LOC='NEW YORK');
The above query results in error.
If I use Where exists
, all rows are deleted in Table A
, which is not a right sol开发者_运维知识库ution.
delete from emp1 a
where exists
( select null
from emp b
where a. empno =b.empno
and b.LOC='NEW YORK'
);
Please suggest
DELETE FROM emp1 a
WHERE a.empno IN
( SELECT b.empno
FROM emp b
WHERE b.LOC = 'NEW YORK'
);
I am not familiar with the MERGE statement, but I will say that emp b isn't properly declared because the b is outside the parenthesis.
Also, I would suggest first making a view (or a temporarily joined table) to be able to see what items match up before executing a DELETE command. Then you can use DELETE based on the view and easily delete from both tables.
精彩评论