Discussion Locked

Removing Duplicates in Access 2000 Query

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a query pulling data from three tables. It counts the total calls of a customer (ORG_ID). My problem s that when I run it, because of the way our database is, I will get the same customer numner twice or more. What kind of critera do I put infor ORG_ID to remove duplicate customer numbers?

13 replies

by kees.valkenswaard

What you are telling does not give much information about the way you have joined the tables. Do you need to join anything at all if the only idea is to get a count? Assuming that ORG_ID is in the table with the calls why not just a simple query with Group By. Press the button with the sigma [the same symbol as auto sum in Excel.] Use Group by for ORG_ID and count for the same or another field.
Maybe you would have to link this query to a table with extra data about the customers.
If that is not your solution, please provide additional information.
Good luck

by nikki96

If I understand correctly...

Use the DISTINCT keyword.

SELECT DISTINCT ORG_ID...
FROM ....

Nikki

by borginva

More info as requested (hope I described it correctly):

I have a query with 3 tables linked: ORG, PRODUCT, SERVICE. They are linked as ORG.ORG_ID to PRODUCT.ORG_ID and ORG.ORG_ID to SERVICE.ORG_ID. ORG_ID is a site's number and in our database, many sites have several PRODUCTS. When I run a query off of those three tables, if a site has 2 different products, it will list the ORG_ID on a spreadsheet 4 times (it will list the ORG_ID 1 time for each product but it will list the same product 2 times).
Ex:
ORG_ID PRODUCT
555 1
555 1
555 2
555 2

How can I prevent this in a query so I can get one PRODUCT per ORG_ID?

by kees.valkenswaard

If the example you give is the result of a query you already made, the rest is extremely simple.
See my previous answer.
Suppose your query is MYOWN
Make a new query based on MYOWN. Just group the results by clicking the sigma button [like the auto sum sign in Excel]
Add both fields to the grid and both will by default get in the Total line of the grid: Group by. Run the query and you will get:
ORG_ID PRODUCT
555 1
555 2
Simple ! ?
Later you can always try to make it more elaborate. However, do not be afraid to build your queries in steps. Thus one part first and use this in another query. In order to avoid problems with multiple tables and joins it is a very safe solution. Only if you have ten thousands and thousands or more records there is a real need to improve your queries.
If this does not satisfy your requirements, it is not necessary to reject this answer. Just add again comment. I have a subscription to this question and I can add comment as well to this answer. If you would not be satisfied by that it is always time enough to reject.
Good luck
Want to mail me? Put also Q&A in the subject line, else the message will be deleted.

by kees.valkenswaard

Reading your additional comment once more, it could be possible that you want to see each ORG_ID for which there is at least one product. If you are not interested in which product, just only a group by on ORG_ID would be sufficient. Alternatives could be to use first or last for PRODUCT. I have the feeling, however, that you were aiming at what I described just above in my second answer.

by kees.valkenswaard

To my humble view, what I described in the answer above is exactly what you want. Why don?t you try it? If you feel it does not work, just add another comment. I will not give up that soon, as long as you make clear where your (real) problem is.

by borginva

Okay, I am being pesty and found some thingts out. GROUP BY has helped a bit and I was playing around and found that when I have ORG_ID for table ORG and PRODUCT from table PRODUCTS, it works. However, when I add in EXPIREDATE form table SERVICE, that is when these dups will not leave, even with GROUP BY. Tables PRODUCTS and SERVICE are not linked (as far as I know).

When the Expiredate.Service is not used, using GROUP BY will give me site 558 (for example) three times showing products 1, 2,3. The way it should be. But when I add I that table, because our database has two contract records, 558 will show each product twice:
558 product 1
558 product 1
558 product 2
558 product 2
558 product 3
558 product 3

So that has been my problem all along and this is what I need fixing.

Am I asking too much or going beyond my original question when I ask this final (trust me) quesiton:

How can duplicates in the query be removed from looking in columns ORG_ID, PRODUCTS, and ExpireDate so that only one copy of that record remains:
558 p1
558 p2
558 p3

Is that possible?

This discussion is closed to new replies.