Malloy1446
asked on
Count UNIQUE results in a field from an MS Access database
I have an MS Access database. I need to get a count of the number of records which have unique results.
There are over 5000 records in the DB. The field is StandardTitle from tblContractJournals,
I need the number of unique titles.
DB example
Redbook
Life
Time
New Yorker
Newsweek
Redbook
Life
Report:
Number of records: 7
Unique Titles: 5
My sql statement is:
sql2 = "Select COUNT(DISTINCT StandardTitle) AS DistinctCount FROM tblContractJournals "
Set objRS2 = Server.CreateObject("ADODB .Recordset ")
objRS2.Open sql2, objConn
SQL statement generates a PAGE cannot display.
There are over 5000 records in the DB. The field is StandardTitle from tblContractJournals,
I need the number of unique titles.
DB example
Redbook
Life
Time
New Yorker
Newsweek
Redbook
Life
Report:
Number of records: 7
Unique Titles: 5
My sql statement is:
sql2 = "Select COUNT(DISTINCT StandardTitle) AS DistinctCount FROM tblContractJournals "
Set objRS2 = Server.CreateObject("ADODB
objRS2.Open sql2, objConn
SQL statement generates a PAGE cannot display.
ASKER
That gives a count of 0.
I do not need to print the unique titles, only need a count.
I do not need to print the unique titles, only need a count.
try this
select Count(A.[StandardTitle]) as DistinctCount
from
(select StandardTitle
from tblContractJournals
group by StandardTitle) as A
select Count(A.[StandardTitle]) as DistinctCount
from
(select StandardTitle
from tblContractJournals
group by StandardTitle) as A
ASKER
I tried your code and am receiving Website cannot display page message.
I used the following with and without the brackets:
I used the following with and without the brackets:
sqlUnique = "Select COUNT(A.StandardTitle) AS Unique " & _
"FROM (Select tblContractJournals Group By StandardTitle) as A "
Set objRSUnique = Server.CreateObject("ADODB.Recordset")
objRSUnique.Open sqlUnique, objConn
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Success! Thank you.
Open in new window