How to find unique values without using distinct function in SQL Server ?

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

I have a table with multiple duplicate values. It has 2 columns: FirstName and LastName . Now I want to select only unique values without using Distinct function. Please help. Thanks

phone · Jan 10, 2019 8:47 PM · 19,510 views

5 Replies

You could use Group by or Union, something like below Select FirstName, LastName, count(*) as Count from Name Group by FirstName, LastName Having Count(*) = 1

Lee_St · Jan 10, 2019 9:20 PM

Thank you Lee_St Almost close but I need 1 unique value from the duplicate value as well. For example:- FirstName LastName A B A B In this case I need the answer only 1 FirstName A and LastName B Using above query removes both A and B.

phone · Jan 11, 2019 9:47 AM

Select FirstName, LastName from Name Group by FirstName, LastName

master_sajha · Jan 11, 2019 3:02 PM

Do not use having clause.

STUPIDA · Jan 11, 2019 3:27 PM

ROW_NUMBER??

28th amendment · Jan 14, 2019 12:37 PM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion