An Aha moment. Thank you
Tim
>The statement you posted is valid. If you fill more comfortable with it than use it.
>
>Now back to EXISTS subquery. It's so called 'correlated query'. It means that one or more colums of the subquery match columns from the main query.
>
>In plain language the query reads: Return all records from Household table WHERE ApplicantID = @PersonId OR any record in HouseholdMembers table with corresponded HouseholdID has PersonId = @PersonId.
>
>
>SELECT *
> FROM Household
> WHERE ApplicantID = @PersonId
> OR EXISTS (SELECT 1 FROM HouseholdMembers WHERE HouseholdID = Household.HouseholdID AND PersonId = @PersonId)
>
>
>>
>>The puzzling part for me was how the primary Select statement gets a match to the subquery. While this probably isn't valid SQL, I would have expected something like this where we specify we are looking for HouseholdID in the subquery to match the HouseholdID in the main query.
>>
>>SELECT *
>> FROM Household
>> WHERE ApplicantID = @PersonId
>> OR HouseholdID = (SELECT HouseholdID FROM HouseholdMembers WHERE PersonId = @PersonId)
>>
>>In that case where trying to specifically select HouseholdID from the subquery.
>>
>>I guess it is this part of the subquery that does that magic. WHERE HouseholdID = Household.HouseholdID AND PersonId = @PersonId
>>
>>Basically it works so I am happy, but just trying to figure out so I understand.
>>Thanks a bunch, I think I am making sense of it now.
Timothy Bryan