SQL Server 2008 select query difficulty -


i have table on 100k records. here issue, have bunch of columns

companyid companyname companyserviceid   servicetypeid    active ---------------------------------------------------------------- 1         xerox       17                 33               yes  2         microsoft   19                 39               yes 3         oracle      22                 54               yes 2         microsoft   19                 36               yes 

so here's how table looks, has 30 other columns irrelevant question.

here's quandary..i'm trying select records companyid , companyserviceid same, can see in table above, have microsoft appears twice in table, , has same companyid , companyserviceid, different servicetypeid.

i need able search records there duplicates. person maintaining data messy , did not update of columns have go through records , find there records have same companyid , companyserviceid.

is there generic query able that?

none of these columns primary key, have column record number increments 1.

you can try this:

   select companyname, count(companyserviceid)     //table name here    group companyname    having ( count(companyserviceid) > 1 ) 

this return grouped list of companies multiple entries. can modify columns want in select statement if need other info record well.


Comments