I have the same *general* problem with a slight twist. In KlineandKing's scenario the name needed to be listed only once for the sum(grade).
In my case there are duplicate ssns in my table, and the fnames and lnames for each occurence of ssn are different and I need to have them listed in the output next to each ssn that has been identified as a duplicate. Please help.
---create table
CREATE TABLE [dbo].[employee](
[empid] [int] IDENTITY(1,1) NOT NULL,
[fname] [varchar](30) NULL,
[lname] [varchar](30) NULL,
[mngrid] [int] NULL,
[ssn] [int] NOT NULL)
---insert data
insert into employee
(fname, lname, mngrid, ssn)
values
('Larry', 'Bechold', 5, 213456123),
('Barry', 'Young', 5, 213456123),
('Rob', 'Sinclaire', 4, 212671777),
('Laban', 'Meese', NULL, 212671777),
('Sarge', 'Lutvok', NULL, 523656667)
---retrieve only rows containing duplicate ssns
select ssn, count(ssn) as countDuplicateSSN
from employee
group by ssn
having COUNT(*)>1;
---results
ssncountDuplicateSSN
2126717772
2134561232
I want output to look like this:
Barry Young 212671777
Laban Meese 212671777
Larry Bechold 213456123
Barry Young 213456123
-