Hi,
Is there any way using SQL I can find the missing rows in the table that I tried to return using a "WHERE...IN()"?
Example query:
SELECT * FROM employees WHERE employee_id IN(100,101,102,103,104,105,106,107,108,109,110);
Suppose the above query returned 8 rows. How can I locate the 3 employee IDs that are absent or missing from the database?
I can look at the output and figure it out, but this is challenging when a few missing rows have to be found from 100+ records.
Looking forward to a better solution.
Thanks in advance
You'll need a data source that contains all the possible values. Then return all those where there NOT EXISTS a match in the target table.
For example:
delete hr.employees
where employee_id in ( 104, 106 );
with rws as (
select 99 + level n from dual
connect by level <= 10
)
select * from rws
where not exists (
select null
from hr.employees
where n = employee_id
);
/*
N
----------
104
106
*/
rollback;