Given the described scheme, I would fetch with a predicate (formatted string), for example @"jobDescription LIKE 'chef'", and then use key coding to get unique values from the resulting array:
[result valueForKeyPath:@"@distinctUnionOfValues.departmentID"];
or create a set:
NSSet *deparmentIDs = [NSSet setWithArray:[result valueForKey:@"departmentID"]];
Depending on the size of the problem (how many employees), the last step in memory may be prohibitive. At this point, you will need to create a unit and do the work to make sure that you have connected the appropriate employees to each department. Then you can make a selection of departments with a predicate (format string), for example @"ANY employees.jobDescription LIKE 'chef'", to get departments with cook employees.
source
share