goofyui
goofyui

Reputation: 3492

Select Distinct Count for First Name, Last Name, DOB in SQL

How to get Distinct Count of First Name, Last Name based on DOB. Assuming that Two persons can share same name but not DOB.

SELECT  COUNT((DISTINCT [First Name], [Last Name], [DOB])) AS TotalCount
FROM    MyTable

Upvotes: 0

Views: 3230

Answers (3)

Pratyush Srivastava
Pratyush Srivastava

Reputation: 1

I think this query could be sufficient to answer this question. It may not be optimal coz I'm just a newbie

select distinct concat([First Name],' ',[Last Name],' ',DOB) from Orders

Upvotes: 0

M.Ali
M.Ali

Reputation: 69554

shouldn't this be as simple as

SELECT [First Name]
      ,[Last Name]
      ,[DOB]
      ,COUNT(*) AS TotalCount
FROM     MyTable
GROUP BY [First Name]
        ,[Last Name]
        ,[DOB]

Upvotes: 2

Dave.Gugg
Dave.Gugg

Reputation: 6781

You should be able to get this info like this:

SELECT  COUNT(1) AS TotalCount
FROM    ( SELECT    [First Name] ,
                    [Last Name] ,
                    [DOB]
          FROM      MyTable
          GROUP BY  [First Name] ,
                    [Last Name] ,
                    [DOB]
        ) a

Upvotes: 2

Related Questions