A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query question



 
 
Thread Tools Display Modes
  #1  
Old May 1st, 2010, 12:41 PM posted to microsoft.public.access.queries
Jeffrey Marks
external usenet poster
 
Posts: 4
Default Query question

I'm having difficulty with a query for a report. I want to report all
the volunteer records (by name) in the volunteer and when they most
recently participated in an event. This is done from a many-to-many
relationship table with events. I only want to pull the last record
for each volunteer (representing the most recently added event). I
also need to list those volunteers who have not ever worked an event
(no relationship table records at all.)

Thanks in advance.

Jeff
  #2  
Old May 1st, 2010, 02:11 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Query question

This would be simplest with 2 queries in tandem.

1. Create a new query, using the related table.

2. Depress the Total button on the toolbar.
Access adds a Total row to the query design grid.

3. In the Total row under the VolunteerID field accept Group By.

4. In the Total row under the date field, choose Max.

5. Test: it should show one row of each volunteer who has done anything,
with the latest date alongside. (Don't output any other fields.) Save the
query, and close it.

6. Create another new query, using your Volunteer table and the query you
just created as input "tables."

7. In the upper pane of table design, double-click the line joining the two
tables. Access pops up a dialog with 3 options. Choose the one that says:
All records from Volunteers, and any matches from Query1.
Technically, this is called an outer join, so you get all volunteers,
whether they have worked or not.

It would be possible (but probably less efficient) to do this in a single
query if you want to learn about subqueries. Here's an intro:
http://allenbrowne.com/subquery-01.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Jeffrey Marks" wrote in message
...
I'm having difficulty with a query for a report. I want to report all
the volunteer records (by name) in the volunteer and when they most
recently participated in an event. This is done from a many-to-many
relationship table with events. I only want to pull the last record
for each volunteer (representing the most recently added event). I
also need to list those volunteers who have not ever worked an event
(no relationship table records at all.)

Thanks in advance.

Jeff


  #3  
Old May 1st, 2010, 02:29 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Query question

Try something like this:

SELECT FirstName, LastName, Event, EventDate
FROM Volunteers, EventVolunteers AS EV1, Events
WHERE EV1.VolunteerID = Volunteers.VolunteerID
AND EV1.EventID = Events.EventID
AND EventDate =
(SELECT MAX(EventDate)
FROM EventVolunteers AS EV2 INNER JOIN Events
ON EV2.EventID = Events.EventID
WHERE EV2.VolunteerID = EV1.VolunteerID)
UNION ALL
SELECT Firstname, LastName, "None", NULL
FROM Volunteers LEFT JOIN EventVolunteers
ON Volunteers.VolunteerID = EventVolunteers.VolunteerID
WHERE EventVolunteers.VolunteerID IS NULL;

Ken Sheridan
Stafford, England

Jeffrey Marks wrote:
I'm having difficulty with a query for a report. I want to report all
the volunteer records (by name) in the volunteer and when they most
recently participated in an event. This is done from a many-to-many
relationship table with events. I only want to pull the last record
for each volunteer (representing the most recently added event). I
also need to list those volunteers who have not ever worked an event
(no relationship table records at all.)

Thanks in advance.

Jeff


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201005/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.