Solved

MS Access Compound Query

Posted on 2014-03-16
2
617 Views
Last Modified: 2014-04-01
Within an MS Access database, I need to filter for unique values in a single table and then produce a count for how many times each of those unique values appeared in the table.

The end goal is a single form in datasheet view that lists each unique value, its current record count, and the target sample size.  I can then apply the appropriate conditional formatting.

I have two tables.  

"table_questions" simply lists all the various questions ('question') in a survey and a number ('sample_size') representing the ideal sample size

"table_reponses" recorded responses to each survey question. The two columns are 'question' and "response'

So basically, I want to create a form in datasheet view that lists the unique questions in the "table_responses" table, count and report each time that question was in the table, and compare that number to the "sample_size" using the "question" as the primary key.

Any thoughts?
0
Comment
Question by:chaddcarr
2 Comments
 

Author Comment

by:chaddcarr
ID: 39933008
As an update, I figured out how to filter for distinct questions only, and produce a count for each:

SELECT
    Question
  , COUNT(*) AS count_distinct_questions
FROM
    ( SELECT DISTINCT
          Question
      FROM tbl_question_count
    ) AS tmp
GROUP BY
    Question;

Now I need to use the Question to query the table_questions table to get the targeted sample size...
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 100 total points
ID: 39933031
Select question, Count(*) As Response_count, sample_size
From table_questions Left Join table_Responses On table_questions.Question = table_Responses.Question
Group by question, sample_size;

This query should get both of the numbers you need.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 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