Delete two non-use entries in statement in Oracle
I am trying to delete two records using the following query in Oracle.
DELETE FROM EMPLOYEE WHERE EMP_ID=1 AND EMP_ID=2;
I know we can delete two records using EMP_ID IN (1,2) statements, but why can't we delete two records using two different EMP_IDs?
You need to use OR
insteadAND
DELETE FROM EMPLOYEE WHERE EMP_ID=1 OR EMP_ID=2;
Please note that EMP_ID = 1 AND
EMP_ID = 2 does not match any records and therefore you are confused. IN is very similar to OR, so your query works with the IN clause since it matches EMP_ID = 1 or EMP_ID = 2;
Try or state :)
EMP_ID=1 OR EMP_ID=2
You can use condition IN
:
DELETE FROM EMPLOYEE WHERE EMP_ID IN(1, 2);
Or use OR
instead AND
:
DELETE FROM EMPLOYEE WHERE EMP_ID=1 OR EMP_ID=2;
Enough code like the following:
DELETE
FROM employee
WHERE emp_id BETWEEN 1 AND 2