Skip to content
Advertisement

How to count distinct records in Access table and display that value in Excel

I have a table in Access that I’m querying from Excel. I need help with the sql statement. First, I need to filter the table based on SampleType matched criteria indicated in the Where clause. There are only 3 options: “mel”, “col” or “ lun”. The ultimate goal is to pass the number of distinct records from the SampleID column for selected SampleType(s) to a variable and output it on a UserForm. SampleType column has duplicate values and need to count only distinct values. From what I’ve found online ‘COUNT(DISTINCT(‘ + column_name + ‘)) would work, but I’m not sure how to use it.

Thanks for your help in advance

Advertisement

Answer

Your question is rather broad, so the answer is sort of generic. Pertinent to the Syntax of MS Access DISTINCT SQL, it could be like the following:

or simplified like:

Corresponding to your additional question in comments, please see the following:

Hope this may help.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement