简体   繁体   中英

Query in a query? (MS Access)

I have a Tasks table for example:

TaskTitle DueDate Person Manager
Report     3/28/15  John   Dave
Inspection 4/10/15  Brian  Shane

and a Contacts Table:

ID   Contact  Email                Manager
1    John     john@company.com     False
2    Dave     dave@company.com     True
3    Brian    brian@company.com    False
4    Shane    shane@company.com    True

And what I want to do is write a query like this:

PEmail            MEmail             TaskTitle 
john@company.com  Dave@company.com   Report
brian@company.com Shane@company.com  Inspection

I can can get the query to select the PEmail or the MEmail, but not both together?

SELECT [Contacts].[Email], [Tasks].[TaskTitle]
FROM tasks
LEFT JOIN [Contacts] 
ON [Tasks].[Person] = [Contacts].[Contact]

and

SELECT [Contacts].[Email], [Tasks].[TaskTitle]
FROM tasks
LEFT JOIN [Contacts] 
ON [tasks].[Manager] = [Contacts].[Contact]

Is there a specific thing this is called? A multiple join or multiple select? I've been really stuck on this.

SELECT [ManagerContacts].[Email] MEmail, 
       [PersonContacts].[Email] PEmail, 
       [Tasks].[TaskTitle]
FROM tasks
    LEFT JOIN [Contacts] ManagerContacts
ON [tasks].[Manager] = [ManagerContacts].[Contact]
    LEFT JOIN [Contacts] PersonContacts
ON [tasks].[Person] = [PersonContacts].[Contact]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM