|
-
Dec 9th, 2012, 05:39 PM
#1
Thread Starter
PowerPoster
get unique records with counts of duplicates?
so I have 2 tables which join together.
I want to know how many records on TrackAudit, between 2 dates, exist and the number of times they exist. how would I do this?
Table Tracks: ID, TrackName, TrackFileName, ArtistID, GenreID
Table Audit: ID, TrackID, DateOfEntry
So Track Audit will have multiple entries for a track but I want a list of each track, within a time period, showing the # of occurances for that track.
-
Dec 9th, 2012, 08:07 PM
#2
Re: get unique records with counts of duplicates?
E.g.
sql Code:
SELECT Tracks.*, COUNT(Audit.TrackID) AS AuditCount FROM Tracks INNER JOIN Audit ON Tracks.TrackID = Audit.TrackID WHERE Audit.DateOfEntry BETWEEN @StartDate AND @EndDate GROUP BY Tracks.*
That will only include those tracks that have at least one audit record in the period. If you want to include every track regardless then you'd have to use an LEFT OUTER JOIN. Also, I'm not sure that you can use a wildcard in the GROUP BY clause like that as I've never actually tried. You may have to write out the full column list but I'm not sure.
-
Dec 10th, 2012, 03:48 AM
#3
Thread Starter
PowerPoster
Re: get unique records with counts of duplicates?
I tried something like that but it did not work - it still gave me the duplicates rather than counting the number of times that track appeared in the query/list
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|