Hi Guys,
I have a problem with a subquery that I can't seem to figure out.
I've built a media database in Access. I'm in the process of creating some queries that will be used for data display purposes. They will be converted to views when the database is upsized to SQL Server.
I have one particular query that is giving me real problems. The query itself is very simple except for one piece which requires a subquery. The query produces basic totals for each Artist:
Total Albums: Count(Title)
Total Songs: Sum(TrackCount)
Total Playing Time: Sum(TotalTime)
I have this part of the query done and it produces the expected values. There is one addition element that I need to add to this query which is the album cover art field for the oldest album for each artist. I use Min(ReleaseYear) to get the Release Year of the oldest album for each Artist. What I'm trying to do is retrieve the Album Cover Art field for this album for each Artist. The field's name is CoverArt and it's an OLE Object field.
I know that I need a subquery to do this and I've tried it every way I can think of with no success.I would prefer to do this in the same query. My subquery skills are a bit rusty and if someone would be kind enough to assist me with this part of the query I would be most grateful.
Here's the query:
Code:
SELECT tblArtists.Artist, Min(tblArtistTitles.YearReleased) AS MinOfYearReleased, Count(tblTitles.Title) AS TotalAlbums, Sum(tblMediaLocations.TrackCount) AS TotalSongs, Sum(tblMedia.TotalTime) AS TotalPlayTime
FROM tblTitles INNER JOIN (((tblArtists INNER JOIN tblArtistTitles ON tblArtists.ArtistID = tblArtistTitles.ArtistID) INNER JOIN tblMediaLocations ON (tblArtistTitles.MediaTypeID = tblMediaLocations.MediaTypeID) AND (tblArtistTitles.YearReleased = tblMediaLocations.YearReleased) AND (tblArtistTitles.TitleID = tblMediaLocations.TitleID) AND (tblArtistTitles.ArtistID = tblMediaLocations.ArtistID)) INNER JOIN tblMedia ON (tblMediaLocations.DiskNumber = tblMedia.DiskNumber) AND (tblMediaLocations.MediaTypeID = tblMedia.MediaTypeID) AND (tblMediaLocations.YearReleased = tblMedia.YearReleased) AND (tblMediaLocations.TitleID = tblMedia.TitleID) AND (tblMediaLocations.ArtistID = tblMedia.ArtistID)) ON tblTitles.TitleID = tblArtistTitles.TitleID
GROUP BY tblArtists.Artist;
Thanks so much for your help.