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?

+3


source to share


4 answers


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;

+3


source


Try or state :)



EMP_ID=1 OR EMP_ID=2

      

+1


source


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;

      

+1


source


Enough code like the following:

DELETE
FROM   employee 
WHERE  emp_id BETWEEN 1 AND 2

      

0


source







All Articles