Link to home
Start Free TrialLog in
Avatar of tommym121
tommym121Flag for Canada

asked on

SQL - How to get unique records based on first and last name from a table

I would like to find out how I can get all the unique records from a table based on the first name and last name
e.g.
First|Last|Address
John|Smith|15 Church St
Holly|Land|1 Charles Cres
John|Smith|15 Church St

The result I hope to get is

First|Last|Address
John|Smith|15 Church St
Holly|Land|1 Charles Cres
Avatar of lcohan
lcohan
Flag of Canada image

You can try a simple
SELECT DISTINCT FirstName,LastName,.... FROM table
ORDER BY FrstName,LastName

and if you still get duplicates then you need to work out a GROUP BY FrstName,LastName instead.
SELECT First, Last, Address FROM Table GROUP BY First,Last,Address
ASKER CERTIFIED SOLUTION
Avatar of Alpesh Patel
Alpesh Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select firstname+' '+lastname AS NAME from temptable
group by firstname,lastname

Open in new window

Avatar of tommym121

ASKER

Thanks