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.
| Author |
Topic |
|
SLM09
Starting Member
31 Posts |
Posted - 2009-10-20 : 14:02:56
|
| Hi all,I am going nuts with this one. I need a query that will return records that have a duplicate value but another value the same.Since it's hard to describe, heres an examplename val1 val2bob 1 1bob 2 2bob 3 2jon 1 1beth 1 1beth 1 2j 1 1j 1 1Here, I would want returned-bob 2 2bob 3 2j 1 1j 1 1I want to return all records where the name is a duplicate AND val2 is a duplicate.I should also mention there are plenty of other fields that are different, so I can just do a full dedup on the record.Any help is really appreciated... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-20 : 14:06:53
|
| [code]select t1.fields...from yourtable t1join (select name,val2 from yourtable group by name,val2 having count(val1)>1)t2on t2.name=t1.nameand t2.val2=t1.val2[/code] |
 |
|
|
SLM09
Starting Member
31 Posts |
Posted - 2009-10-20 : 14:58:18
|
| That worked like a charm!Thank you Visakh! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-20 : 15:11:50
|
| welcome |
 |
|
|
|
|
|