Select Query Joined on Two Fields?

Posted by btollett on Stack Overflow See other posts from Stack Overflow or by btollett
Published on 2010-04-30T17:28:55Z Indexed on 2010/04/30 17:47 UTC
Read the original article Hit count: 153

Filed under:
|
|
|

I've got a few tables in an access database:

ID | LocationName
1  | Location1
2  | Location2

ID | LocationID | Date  | NumProductsDelivered
1  |     1      | 12/10 |      3
2  |     1      | 01/11 |      2
3  |     1      | 02/11 |      2
4  |     2      | 11/10 |      1
5  |     2      | 12/10 |      1

ID | LocationID | Date  | NumEmployees | EmployeeType
1  |     1      | 12/10 |      10      |      1 (=Permanent)
2  |     1      | 12/10 |       3      |      2 (=Temporary)
3  |     1      | 12/10 |       1      |      3 (=Support)
4  |     2      | 10/10 |       1      |      1
5  |     2      | 11/10 |       2      |      1
6  |     2      | 11/10 |       1      |      2
7  |     2      | 11/10 |       1      |      3
8  |     2      | 12/10 |       2      |      1
9  |     2      | 12/10 |       1      |      3

What I want to do is pass in the LocationID as a parameter and get back something like the following table. So, if I pass in 2 as my LocationID, I should get:

Date  | NumProductsDelivered | NumPermanentEmployees | NumSupportEmployees
10/10 |                      |           1           |           
11/10 |          1           |           2           |          1
12/10 |          1           |           2           |          1

It seems like this should be a pretty simple query. I really don't even need the first table except as a way to fill in the combo box on the form from which the user chooses which location they want a report for. Unfortunately, everything I've done has resulted in me getting a lot more data than I should be getting. My confusion is in how to set up the join (presumably that's what I'm looking for here) given that I want both the date and locationID to be the same for each row in the result set.

Any help would be much appreciated.

Thanks.

© Stack Overflow or respective owner

Related posts about ms-access

Related posts about sql