Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Duplicate Ori_File_Name and their Doc_IDs

Author  Topic 

10Dawg
Starting Member

46 Posts

Posted - 2011-01-31 : 16:36:55
SELECT Ori_File_Name
FROM Review_Doc
GROUP BY Ori_File_Name
HAVING Count(Ori_File_Name) > 1

and

SELECT Ori_File_Name, Doc_ID
FROM Review_Doc

both work but.....

SELECT Ori_File_Name, Doc_ID
FROM Review_Doc
GROUP BY Ori_File_Name
HAVING Count(Ori_File_Name) > 1

does not work and gives an error message:

Msg 8120, Level 16, State 1, Line 1
Column 'Review_Doc.Doc_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I need a list of Duplicate Ori_File_Name and their associated Doc_IDs. What am I doing wrong?

10Dawg

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-31 : 16:51:12
SELECT Ori_File_Name, Doc_ID
FROM Review_Doc
where Ori_File_Name in(
SELECT Ori_File_Name
FROM Review_Doc
GROUP BY Ori_File_Name
HAVING Count(Ori_File_Name) > 1
)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -