I want to find out all the employees who have the same number of children as the employees of department 111 and who were born between the years 1968 and 1969. So if in the department I have employees who have 1 and 2 children, the result of the query should be all the employees born on that date and who have 1 and 2 children
With this query i find out employees born in those years
select *
from temple
where fecna between '1968-01-01' and '1969-12-31';
And here I find out all types of number of children in department 111
select distinct numhi
from temple
where numde = 111;
The result should be something like this
I tried to join both select but returns wrong data
>Solution :
You could use the second query in a join condition like:
select t1.*,
from temple t1
inner join (
select distinct numhi
from temple
where numde = 111
) as t2 on t1.numhi=t2.numhi
where t1.fecna between '1968-01-01' and '1969-12-31';
Please read MySQL JOIN and subquery