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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-09-20 : 10:23:40

I have a table as follows:

Group DocName Language URI
----------------------------------------------------------
GroupA Bob En http://bogus
GroupA Bob En http://bogus
GroupA Fred En http://another
GroupA Fred En http://bad
GroupB Susi En http://test
GroupB Susi En http://test


I need a listing of all identical DocNames within each Group that has different URI values without using a cursor.

i.e. for the above data I would want the following records to come out:

Group DocName Language URI
----------------------------------------------------------
GroupA Fred En http://another
GroupA Fred En http://bad

Thanks,
Kabir

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-09-20 : 10:44:34
SELECT b.*
FROM
(select [group],DocName,count(*)
from yourtable
group by [group],DocName
having count(*) > 1
) a

INNER JOIN yourtable b
ON
a.group = b.group
and a.docname = b.docname

Jim
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-21 : 05:08:11
quote:
Originally posted by jimf

SELECT b.*
FROM
(select [group],DocName,count(*) as counts
from yourtable
group by [group],DocName
having count( DISTINCT URI) > 1
) a

INNER JOIN yourtable b
ON
a.group = b.group
and a.docname = b.docname

Jim



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-09-21 : 09:01:47

Thanks. That works a treat.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-21 : 09:23:09
Note that most of the time, you can do the things without using a cursor as explained

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -