Turn two queries into one with a subquery ACCESS 2010

I have two queries, but I want to turn them into one with a subquery, but not sure how to do it.  Below are the two queries.  I am trying to get the PersonID to display in a combobox that are NOT in tblCaseSatisfactionSurvey

SELECT DISTINCT tblCase.CaseID, tblCase.PersonID, [FirstName] & " " & [LastName] AS [Full Name], tblPerson.DOB
FROM (tblCase INNER JOIN tblPerson ON tblCase.[PersonID] = tblPerson.[PersonID]) INNER JOIN qumPersonId ON tblPerson.PersonID = qumPersonId.PersonID
ORDER BY tblCase.PersonID;


SELECT tblPerson.PersonID
FROM tblPerson LEFT JOIN tblCaseSatisfactionSurvey ON tblPerson.[PersonID] = tblCaseSatisfactionSurvey.[PersonID]
WHERE (((tblCaseSatisfactionSurvey.PersonID) Is Null));
Sandra SmithRetiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
You are leaving a great deal to our intuition (i.e. we have to guess). It would be better to illustrate what you want using a sample of data from each existing query and then the expected result once combined.

Having said that, this is my first guess:
SELECT DISTINCT
      tblCase.CaseID
    , tblCase.PersonID
    , p.[FirstName] & " " & p.[LastName] AS [Full Name]
    , p.DOB
    , p.[InSurvey]
FROM (tblCase
      INNER JOIN (
                SELECT
                      tblPerson.PersonID, tblPerson.FirstName, tblPerson.LastName, tblPerson.DOB
                      , IIF(tblCaseSatisfactionSurvey.[PersonID] IS NULL, 'No', 'Yes') AS [InSurvey]
                FROM tblPerson
                      LEFT JOIN tblCaseSatisfactionSurvey ON tblPerson.[PersonID] = tblCaseSatisfactionSurvey.[PersonID]
                ) p ON tblCase.[PersonID] = p.[PersonID])
ORDER BY tblCase.PersonID;

Open in new window

0
Mike EghtebasDatabase and Application DeveloperCommented:
Hi Paul,

Unlike SQL Server, Access has all-at-once ability; therefore using derived expression may not be necessary (or understood) by Access.

I tried to transform your code by removing the derived expression part but I thought I leave it to you because you have already thought through the logic. If you like to do this,  ssmith94015 could give it a try.

I don't think derived expression would work at least be able to display in QBE interface where its use is a very common practice in MS Access.

BTW, a self-contained or a correlated subquery will work in Access.

Mike
0
PortletPaulfreelancerCommented:
Thanks Mike, perhaps this will work (guess two)
SELECT DISTINCT
      tblCase.CaseID
    , tblCase.PersonID
    , p.[FirstName] & " " & p.[LastName] AS [Full Name]
    , p.DOB
    , IIF(tblCaseSatisfactionSurvey.[PersonID] IS NULL, 'No', 'Yes') AS [InSurvey]
FROM (tblCase
      INNER JOIN tblPerson p  ON tblCase.[PersonID] = p.[PersonID]
      LEFT JOIN tblCaseSatisfactionSurvey ON tblPerson.[PersonID] = tblCaseSatisfactionSurvey.[PersonID] ON tblCase.[PersonID] = p.[PersonID])
ORDER BY tblCase.PersonID;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sandra SmithRetiredAuthor Commented:
Both pieces of information helped, thank you.  It does what I want without the need for more than one query.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.