Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't update a field from a query result due to 'Group By'

Status
Not open for further replies.

MattGreer

Technical User
Feb 19, 2004
471
0
0
US
Using MS Access 365. I have a query that counts the number of times a song has been performed given a date range entered by the user (just me). What I would like to be able to do, however, is update a Yes/No field from within that query. I went about a bit of trial and error and it seems that the aggregate function (if I'm using that term correctly) 'Group By', which seems to be required for this query to run, prevents any updates to that particular field. (The field in question is 'SheetMusic'.)

Is there a way to create a query that would allow me to update that field?

Code:
SELECT Count(tblSongsPlayed.SongID) AS [Song Count], tblSongs.Title, tblSongs.SheetMusic
FROM tblSongs INNER JOIN (tblEvents INNER JOIN tblSongsPlayed ON tblEvents.EventID = tblSongsPlayed.EventID) ON tblSongs.SongID = tblSongsPlayed.SongID
WHERE (((tblEvents.Date)>=DateAdd("yyyy",-1*[How Many Years Back Do You Want To Go?],Now())))
GROUP BY tblSongs.Title, tblSongs.SheetMusic
ORDER BY Count(tblSongsPlayed.SongID) DESC;

Screenshot of the 'Design View' in MS Access:

Thanks!!

Matt
 
You can use two tables on the right (screenshot) to perform calculations in a separate query, in new query link it with tblSongs without grouping.

combo
 
I wonder if grabbing the total from a subquery would work.

SQL:
SELECT tblSongs.Title, tblSongs.SheetMusic, 
(SELECT Count(tblSongsPlayed.SongID) AS [Song Count]
 FROM tblEvents INNER JOIN tblSongsPlayed ON tblEvents.EventID = tblSongsPlayed.EventID 
 WHERE tblSong.SongID = tblSongsPlayed.SongID AND tblEvents.Date>=DateAdd("yyyy",-1*[How Many Years Back Do You Want To Go?],Now())) AS SongCount
FROM tblSongs;

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top