Hey all - just found this site and I am hoping you can help me with a problem I am having constructing a query for a MS Access 2007 database. I have 3 tables of data simplified as follows
- persons: personID, name
- data1: personID, week, year, place, value
- data2: personID, week, year, value
The persons table is required, but, for a given week and year, the person can have data in either data1, data2, or both. I'd prefer not to combine the data1 and data2 tables since the person will often have many data1 values for a given week/year, but at most 1 data2 value for the same week/year.
I'd like to grab the persons.name, data1.place, data1.value and data2.value for a given week and year as long as there is a value for that week and year in either data1 or data2. Any help would be appreciated!
My current query is as follows:
Using dummy data in the database, I get the following results:
1) If I have data in data1 for only 1 person but not in data2 for the week/year, it returns ALL the persons, along with the correct data in data1 and data2 (null) - I would prefer to just have persons with values in data1 or data2
2) If I have data in data2 for a given person, but not in data1 for the given week/year, I get a "Join expression not supported" error.
Thanks again for your help!
- persons: personID, name
- data1: personID, week, year, place, value
- data2: personID, week, year, value
The persons table is required, but, for a given week and year, the person can have data in either data1, data2, or both. I'd prefer not to combine the data1 and data2 tables since the person will often have many data1 values for a given week/year, but at most 1 data2 value for the same week/year.
I'd like to grab the persons.name, data1.place, data1.value and data2.value for a given week and year as long as there is a value for that week and year in either data1 or data2. Any help would be appreciated!
My current query is as follows:
Code:
SELECT persons.name, data1.place, data1.value, data2.value FROM (persons LEFT JOIN data1 ON (persons.personID = data1.personID AND data1.week = 1 AND data1.year = 2010)) LEFT JOIN data2 ON (persons.personID = data2.personID AND data2.week = 1 AND dats2.year = 2010)
1) If I have data in data1 for only 1 person but not in data2 for the week/year, it returns ALL the persons, along with the correct data in data1 and data2 (null) - I would prefer to just have persons with values in data1 or data2
2) If I have data in data2 for a given person, but not in data1 for the given week/year, I get a "Join expression not supported" error.
Thanks again for your help!
Comment