Solved

count(distinct) in MS Access

Posted on 1998-07-31
2
1,031 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 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