I have a workers table and an associated workerGeofence table.
CREATE TABLE IF NOT EXISTS `workergeofences` (
`ID` int(11) NOT NULL,
`WorkerID` varchar(20) NOT NULL,
`GeofenceID` int(11) NOT NULL,
`isActive` tinyint(4) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=latin1;
I need to return only workers who have at least one entry in the workerGeofences table with an isActive of 1.
I'm able to get the desired outcome withe following:
SELECT distinct w.ID, Title, FName, SName, Email, Birthday, Address, Phone, description,
companyID
FROM Workers w WHERE companyID = ?
and w.ID IN (SELECT WorkerID FROM WorkerGeofences WHERE isActive <> 0)
limit ?,10
but the in subquery is exhaustive as when I run the explain, I can see it is scanning the entire table. How would I get around this?