sql - Return list of emp # NOT in a query, Access 2007 -


have table of list of problems people can have. these people id'd number. these people can have number of problems (usually 5-10). want list of people tobacco not appear problem them. solution going to make query of people have tobacco problems, , query query statement return numbers not in tobacco query. done? close?

query list of people have tobacco problems

select distinct person.personid tblkentuckycounties inner join (tblcomorbidity inner join (person inner join tblcomorbidityperson on person.personid = tblcomorbidityperson.personid) on tblcomorbidity.id = tblcomorbidityperson.comorbidityfk) on tblkentuckycounties.id = person.county ((not (tblcomorbidity.comorbidityexplanation)="tobacco")); 

query want return people not in first query

select  person.personid expr1, [tobacco query].personid [tobacco query] inner join person on [tobacco query].personid = person.personid; 

i not savvy on access sql dialect, want left join, not inner join. left join inner join in give rows left-hand side of join (in case, person table), joined matching rows on right-hand side of join. left join give rows left-hand side don't have matching rows on right-hand side. subset of rows, right-hand side columns have null values.

so should able write:

select  person.personid expr1, [tobacco query].personid person left join [tobacco query] on [tobacco query].personid = person.personid [tobacco query].personid null; 

that eliminate every record except ones couldn't find matching record in [tobacco query], should ones you're looking for.

edit: had person table on right @ first... left join should on left, since that's table want data from.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -