简体   繁体   English

在查询中查询? (MS Access)

[英]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? 我可以查询选择PEmail或MEmail,但不能同时选择两者?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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