| Author |
Topic |
|
rickrat
Starting Member
2 Posts |
Posted - 2008-04-22 : 03:01:25
|
I have a table with DiscNo, Artist, Title and other fields. I would like to find all duplicate records with the same artist/title and with the first 3 characters of the discnumber. e.g.SELECT Artist, Title Into #TempArtistTitle FROM MediaFile GROUP BY Artist, TitleHAVING COUNT(SubString(DiscNo, 0, 3)) > 1SELECT MediaFile.DiscNo, MediaFile.Artist, MediaFile.Title FROM MediaFile RIGHT OUTER JOIN #TempArtistTitle ON MediaFile.Title = #TempArtistTitle.Title AND MediaFile.Artist = #TempArtistTitle.Artist ORDER BY Artist, Title, DiscNoDrop TABLE #TempArtistTitleGO See, if the first 3 characters of the disc number is the same, it is the same manufacturer. This query works somewhat, although it returns records that the discnumber is unique too. Like below, the LG disc number shouldn't be returned, as there is only one record for that artist/title.SC8151-10 - Garth Brooks - Friends In Low PlacesSC8125-04 - Garth Brooks - Friends In Low PlacesLG5003-07 - Garth Brooks - Friends In Low Places Could someone help me please? |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-04-22 : 03:29:14
|
| try this,Select * From (SELECT DiscNo, Artist, title, Row_Number() over(Partition by Artist, title, SubString(DiscNo, 0, 3) order by DiscNo) as 'Row'FROM MediaFile) AWHere Row > 1 |
 |
|
|
rickrat
Starting Member
2 Posts |
Posted - 2008-04-22 : 03:31:17
|
quote: Originally posted by PeterNeo try this,Select * From (SELECT DiscNo, Artist, title, Row_Number() over(Partition by Artist, title, SubString(DiscNo, 0, 3) order by DiscNo) as 'Row'FROM MediaFile) AWHere Row > 1
I love you! This works, but as my fixed post above, it still returns records with only one instance of a disc number too. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-22 : 04:15:46
|
What about this:-SELECT MediaFile.DiscNo, MediaFile.Artist, MediaFile.Title FROM MediaFile INNER JOIN (SELECT SubString(DiscNo, 0, 3) AS DiscNo,Artist, Title Into #TempArtistTitle FROM MediaFile GROUP BY SubString(DiscNo, 0, 3),Artist, TitleHAVING COUNT(*) > 1)tempON MediaFile.Title = temp.Title AND MediaFile.Artist = temp.Artist AND SubString(MediaFile.DiscNo, 0, 3)=t.DiscNoORDER BY MediaFile.DiscNo, MediaFile.Artist, MediaFile.Title |
 |
|
|
|
|
|