Results 1 to 3 of 3

Thread: get unique records with counts of duplicates?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: get unique records with counts of duplicates?

    E.g.
    sql Code:
    1. SELECT Tracks.*, COUNT(Audit.TrackID) AS AuditCount
    2. FROM Tracks
    3. INNER JOIN Audit
    4. ON Tracks.TrackID = Audit.TrackID
    5. WHERE Audit.DateOfEntry BETWEEN @StartDate AND @EndDate
    6. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width