I have the following table with two fields namely a and b as shown below:
create table employe ( empID varchar(10), department varchar(10) );
try this
select empID from employe where empId in (select empId from employe where department = 'Z' and department = 'Y') and empId not in (select empId from employe where department = 'X') ;