Solved

count query question - access

Posted on 2013-01-21
5
380 Views
Last Modified: 2013-01-21
I want to write a query that will count the number of clients on a certain class of drugs.
Then if they have more than 2 of those drugs on their profile, I want this on output. If they dont have 2 or more, I dont want them.

 I would love to do this in one query but I am thinking I have to make 2 queries.  One to count the drugs, then another one to ADD other information such as name, date, drug name .....

I have 2 tables I am gathering information from - ORDERS and Clients.  The Client number is a unique client identifier.

Criteria needed: End query must show clients who are on 2 or more drugs that start with the Thera_code of 08. The drug must not be stopped (NO in the Stopped column)

I have tried placing the "count" in the query, but I just cant get it to work!  I have attached the database for reference.


Here is the SQL without the COUNT:
SELECT CLIENTS.Client_NUM, ORDERS.THER_CODE_1, CLIENTS.NRS_STATION, CLIENTS.BED_ABBREV, CLIENTS.PTNAME, CLIENTS.PAT_NUM, ORDERS.DRUG_CODE, ORDERS.BRAND_NAME, ORDERS.GENERIC_NAME, ORDERS.STOPPED
FROM CLIENTS INNER JOIN ORDERS ON CLIENTS.Client_NUM = ORDERS.Client_NUM
WHERE (((ORDERS.THER_CODE_1) Like "08*") AND ((ORDERS.STOPPED)="NO"));
database--2-.mdb
0
Comment
Question by:joylene6
[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
  • 4
5 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38803469
you can use the wizard to create the query, select the find duplicates query


test the query Find Duplicates
database--2-.mdb
0
 
LVL 1

Author Comment

by:joylene6
ID: 38803513
I ranthis.

So you used the find duplicates wizzard..... I see in the Query in design view it has

In (SELECT [Client_NUM] FROM [DRUG Qry] As Tmp GROUP BY [Client_NUM],[THER_CODE_1] HAVING Count(*)>1  And [THER_CODE_1] = [DRUG Qry].[THER_CODE_1])

If I just want entries with more than 2 should I change to

In (SELECT [Client_NUM] FROM [DRUG Qry] As Tmp GROUP BY [Client_NUM],[THER_CODE_1] HAVING Count(*)>2  And [THER_CODE_1] = [DRUG Qry].[THER_CODE_1])
0
 
LVL 1

Author Comment

by:joylene6
ID: 38803522
Now if I want to modify this further to make only ONE of each drug code show..... do I do a MAX on the drug code? ( drug code is a unique identifier for each drug)

For example client is on 3 of drug A and 2 of drug B..... I just want one line of A and one line of B to show.
0
 
LVL 1

Author Comment

by:joylene6
ID: 38803523
the HAVING Count(*)>2 worked btw
0
 
LVL 1

Author Closing Comment

by:joylene6
ID: 38803861
Thank you. using your example I was able to complete my query.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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