title: Performing lookup on multiple entities using NSPredicate
body: <p>I've run into a problem when I've been porting my code over from a SQLite database to Core Data.</p>
  
  <p>The data that I'm using comes from a existing database and as such has all the relationships defined using the ID of each of the tables (or entities now that I'm using Core Data). My problem is that I want to query against a single table then use that result to propagate up though the data to get all the other data that I require.</p>
  
  <p>The original database looks like:</p>
  
  <pre><code>CREATE TABLE TecAccessPoints (MAC varchar NOT NULL PRIMARY KEY UNIQUE,ZoneID integer NOT NULL,Floor integer);
  CREATE TABLE Zones (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,ZoneName varchar NOT NULL,BuildingID integer,ZoneDescription varchar);
  CREATE TABLE Buildings (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT,BuildingName varchar NOT NULL,CampusID integer NOT NULL,BuildingDescription varchar,Long float,Lat float);
  CREATE TABLE Campuses (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,CampusName varchar NOT NULL,CampusDescription text, Latitude float, Longitude float);
  </code></pre>
  
  <p>My original SQL query is:</p>
  
  <pre><code>SELECT DISTINCT Zones.ID, Zones.ZoneName, Buildings.ID, Buildings.BuildingName, Campuses.ID, Campuses.CampusName, Rooms.ID, Rooms.NameNumber, Rooms.Floor 
  FROM Zones, TecAccessPoints, Buildings, Campuses, Rooms 
  WHERE Campuses.ID = Buildings.CampusID 
     AND Buildings.ID = Zones.BuildingID 
     AND Zones.ID = Rooms.ZoneID 
     AND Zones.ID = TecAccessPoints.ZoneID 
     AND TecAccessPoints.MAC = '%@';
  </code></pre>
  
  <p>Is there any way that I can replicate this query using NSPredicate (or something similar) or is it the case that I'll have to first perform the lookup</p>
  
  <pre><code>TecAccessPoints.MAC == '%@'
  </code></pre>
  
  <p>Then do another lookup on the data using the returned data like:</p>
  
  <pre><code>Zones.ID == TecAccessPoints.ZoneID
  </code></pre>
  
  <p>And so on until I have all my results that I need?</p>
  
  <p>Thanks</p>
  
  <p>James</p>