Solved

count(distinct) in MS Access

Posted on 1998-07-31
2
1,023 Views
Last Modified: 2008-03-10
I'm developing an application which is eventually to be ported into Oracle database,
but currently I'm doing debugging with MS Access, since it's easier to setup and verify
what's going on.  The problem I encountered is Access doesn't seem to understand
the count(distinct) in the query.  In particular, my query is

SELECT COUNT(DISTINCT VarMatrixRow) FROM DecVariables

When running this, I'm getting the error

Syntax error (missing operator) in query expression 'COUNT(DISTINCT VarMatrixRow)'

Of course, I can go around it and write a code to count the number of distinct things in the table,
but that's not very efficient, especially since I'll be moving this to Oracle soon.  Any ideas?
0
Comment
Question by:shchuka
2 Comments
 
LVL 1

Accepted Solution

by:
Anita030598 earned 10 total points
ID: 1957756
Yes, that fails in Access. However you can do that using two queries.

SELECT DISTINCT VarMatrixRow FROM DecVariables;
 - Say, you called it as Query1

Then write your next query as
SELECT Count(Query1.VarMatrixRow) AS VMRCount FROM Query1;

But, I don't know how it effects in Oracle.

0
 
LVL 2

Author Comment

by:shchuka
ID: 1957757
I knew about this one.  My idea is to do it in one query.  I need to do that 12 times in each iteration of a loop; the loop may iterate anywhere between 4 and 10 times, thus increasing the number of queries from potentially 120 to 240 - which is unacceptable in terms of performance.  Moreover, the

select count(x) from (select (distinct VarMatrixRow) x from DecVariables)

also fails in Access, since Access doesn't understand subqueries.

Thanks anyway.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to call a sub using a string variable? 20 57
Splitting out Data 14 27
Resize text 4 16
Run SQL statement in Microsoft Access 9 14
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now