My suggestion about using distinct was incorrect. MichaelJSQL's query produces exactly the output you specified in your original posting. If you are not getting it, copy and paste this query and run it. Then compare with your actual data to see what might be different.CREATE TABLE #test(chapterId INT, xmlfile VARCHAR(32));INSERT INTO #test VALUES(1234,'123.xml'),(1234,'123.xml'),(1234,'123.xml'),(1234,'123.xml'),(4567,'123.xml'),(4567,'123.xml'),(6789,'145.xml'),(7890,'234.xml'),(7890,'234.xml'),(7890,'234.xml');SELECT chapterid , xmlfileFROM #testGROUP BY chapterid , xmlfile;SELECT chapterId , xmlfileFROM #testGROUP BY chapterId , xmlfileHAVING COUNT(chapterid) > 1;DROP TABLE #test;