Good day. Suppose I have this info:
Empleados:
ID----NOMBRE
1-----JUAN
2-----PABLO
NominaEmpleados
ID----IDEmpleado
1-----2
I am trying to do a query that returns the employee that is not yet in the NominaEmpleados table. How can I get this data?
I have something like this in mind, but it doesn't do what I need:
select e.* from empleados e, Nominas_Empleados ne where ne.Id_Nomina=1 and e.Id not in(ne.Id_Empleado)
You were on the right track, with one
NOT IN
you would have to do the following:Now, if
NominaEmpleados
there were any in the tableNULL
, you would have unexpected results. For the same reason, I recommend you useNOT EXISTS
in these cases:This query returns all the employees whose id is not found in the subquery that analyzes the payroll of the employees