Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Counting unique rows

Author  Topic 

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2007-12-18 : 11:23:24
I have a table of names in which some names are repeted. I need to count the number of unique names. DISTINCT will return the unique rows. Now I need to count them. I think I am on the right track but can't get the syntex right.

Where am i going wrong?

select count(*) from Names where (select distinct First_Name, Last_Name from Names)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-18 : 11:25:43
Try this

select COUNT(DISTINCT First_Name,Last_Name) from Names
Go to Top of Page

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2007-12-18 : 11:28:54
Statement :
select COUNT(DISTINCT First_Name,Last_Name) from Names

returns this error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
Go to Top of Page

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2007-12-18 : 11:38:56
This seems to work:

select COUNT(DISTINCT First_Name + Last_Name) from Names

Thanks. You got me looking in the right place for the solution.
Go to Top of Page
   

- Advertisement -