duplicates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that returns duplicates based on two variables.
Inmate#
Product
What I need is if the Inmate has 4 or more of the same item then it gives me
the results, it if is less than or =3 then it does not display them in the
query.

Can this be done.

Here is my code.
SELECT tblProperty.[Inmate#], tblProperty.Product, tblProperty.ID,
tblProperty.Quantity, tblProperty.Date, tblProperty.Description,
tblProperty.[Order#], tblProperty.[Serial#]
FROM tblProperty
WHERE (((tblProperty.[Inmate#]) In (SELECT [Inmate#] FROM [tblProperty] As
Tmp GROUP BY [Inmate#],[Product] HAVING Count(*)>1 And [Product] =
[tblProperty].[Product])))
ORDER BY tblProperty.[Inmate#], tblProperty.Product;
 
If I understand you correctly all you should need to do is to change the
HAVING COUNT(*) > 1 to HAVING Count(*) > 3

SELECT tblProperty.[Inmate#], tblProperty.Product, tblProperty.ID,
tblProperty.Quantity, tblProperty.Date, tblProperty.Description,
tblProperty.[Order#], tblProperty.[Serial#]
FROM tblProperty
WHERE (((tblProperty.[Inmate#]) In (SELECT [Inmate#]
FROM [tblProperty] As Tmp
GROUP BY [Inmate#],[Product]
HAVING Count(*)>3 And [Product] =
[tblProperty].[Product])))
ORDER BY tblProperty.[Inmate#], tblProperty.Product;

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Works great thanks

John Spencer said:
If I understand you correctly all you should need to do is to change the
HAVING COUNT(*) > 1 to HAVING Count(*) > 3

SELECT tblProperty.[Inmate#], tblProperty.Product, tblProperty.ID,
tblProperty.Quantity, tblProperty.Date, tblProperty.Description,
tblProperty.[Order#], tblProperty.[Serial#]
FROM tblProperty
WHERE (((tblProperty.[Inmate#]) In (SELECT [Inmate#]
FROM [tblProperty] As Tmp
GROUP BY [Inmate#],[Product]
HAVING Count(*)>3 And [Product] =
[tblProperty].[Product])))
ORDER BY tblProperty.[Inmate#], tblProperty.Product;

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Michelle said:
I have a query that returns duplicates based on two variables.
Inmate#
Product
What I need is if the Inmate has 4 or more of the same item then it gives
me
the results, it if is less than or =3 then it does not display them in the
query.

Can this be done.

Here is my code.
SELECT tblProperty.[Inmate#], tblProperty.Product, tblProperty.ID,
tblProperty.Quantity, tblProperty.Date, tblProperty.Description,
tblProperty.[Order#], tblProperty.[Serial#]
FROM tblProperty
WHERE (((tblProperty.[Inmate#]) In (SELECT [Inmate#] FROM [tblProperty] As
Tmp GROUP BY [Inmate#],[Product] HAVING Count(*)>1 And [Product] =
[tblProperty].[Product])))
ORDER BY tblProperty.[Inmate#], tblProperty.Product;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Max Date Query Part 2 4
Help with queries 1
Lookup 5
Sum in Report Errors 3
Subform Nightmare.. 6
Subform Dilemma 2
User-defined fields 6
help with a query (probably simple) 4

Back
Top