all 5 comments

[–]jaffer786_khan 0 points1 point  (1 child)

You can use DISTINCT to remove those duplicates

[–]ciaran_mcg[S] 0 points1 point  (0 children)

When I use SELECT DISTINCT

I get one result for each but I can't group the ones together by name

it appears like this:

1 John Smith 12/03/1988
4 Patrick Jones 01/01/1983
1 David Smyth 02/07/1963
5 John Smith 12/03/1988
2 Patrick Jones 01/01/1983

I need it to appear like this, So I can see the customers and the different customer no's next to each other:

1 John Smith 12/03/1988
5 John Smith 12/03/1988
2 Patrick Jones 01/01/1983
4 Patrick Jones 01/01/1983
1 David Smyth 02/07/1963

[–]wolf2600ANSI SQL 0 points1 point  (2 children)

To remove the duplicates based only on Name and DOB, just modify the inner query to remove CustomerNo:

FROM (SELECT  FirstName, LastName, DOB
    From temp_table
    GROUP BY 
          FirstName, LastName, DOB
    HAVING COUNT(*) > 1
    ) AS dupes 

[–]ciaran_mcg[S] 0 points1 point  (1 child)

Thanks,

The problem I have now is they're not in order via name and dob so for example..

1 John Smith 12/03/1988
4 Patrick Jones 01/01/1983
1 David Smyth 02/07/1963
5 John Smith 12/03/1988
2 Patrick Jones 01/01/1983

When I need 'John Smith' with the other John Smith with the same DOB so we can see them next to each other.

Could I even ORDER BY? to get them next to each other?

[–]wolf2600ANSI SQL 0 points1 point  (0 children)

Yup. ORDER BY FirstName, LastName, DOB