Trying to do a not in for a select statement but it returns all the rows in tblHomeOwnerJobHistory with the exception of plumber using the SQL below, I don’t want anything being retrieved for that Home. Any ideas?
select *
from tblHome, tblHomeOwner, tblHomeOwnerJobHistory
where tblHome.id=1
and tblHomeOwner.homeid = tblHome.id
and tblHomeOwner.id = tblHomeOwnerJobHistory.homeownerid
and tblHomeOwnerJobHistory.retired = 'NO'
and tblHomeOwnerJobHistory.Job not in plumber
Is plumber a field in either tblHome, tblHomeOwner or tblHomeOwnerJobHistory tables?
The query should look more like this:
select *
from tblHome, tblHomeOwner, tblHomeOwnerJobHistory
where tblHome.id=1
and tblHomeOwner.homeid = tblHome.id
and tblHomeOwner.id = tblHomeOwnerJobHistory.homeownerid
and tblHomeOwnerJobHistory.retired = 'NO'
and tblHomeOwnerJobHistory.Job not in ('plumber')
SELECT something
, anything
, just_not_the_dreaded_evil_select_star
FROM tblHome
INNER
JOIN tblHomeOwner
ON tblHomeOwner.homeid = tblHome.id
INNER
JOIN tblHomeOwnerJobHistory
ON tblHomeOwnerJobHistory.homeownerid = tblHomeOwner.id
AND tblHomeOwnerJobHistory.retired = 'NO'
AND tblHomeOwnerJobHistory.Job not in ('plumber')
WHERE tblHome.id = 1
Thanks for the suggestions, but this is retrieving the same results. If you think about the example table structures below, it will currently return rows that are not plumber (i.e. doing the query against tblHome=1 as suggested will bring back singer, phone operator, webdesign rows), but instead I only want it to return any tblHome=1 related information only if plumber isn’t listed against it.
SELECT something
, anything
, just_not_the_dreaded_evil_select_star
FROM tblHome
INNER
JOIN tblHomeOwner
ON tblHomeOwner.homeid = tblHome.id
INNER
JOIN tblHomeOwnerJobHistory
ON tblHomeOwnerJobHistory.homeownerid = tblHomeOwner.id
AND tblHomeOwnerJobHistory.retired = 'NO'
WHERE tblHome.id = 1
AND NOT EXISTS
( SELECT 'uh oh'
FROM tblHomeOwnerJobHistory
WHERE homeownerid = tblHomeOwner.id
AND Job = 'plumber' )