A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

The not "Max" records



 
 
Thread Tools Display Modes
  #1  
Old May 12th, 2010, 04:57 PM posted to microsoft.public.access.queries
Iram
external usenet poster
 
Posts: 122
Default The not "Max" records

Hello,
I have a query that finds all records with a particular "Case#". I changed
the query to do totals and grouped by Case#'s. I have another field called
"PrisonID" in which I want to see all records except for the Max (except the
highest number PrisonID). Eventually I need to change this query into a
delete query so that it automatically deletes all duplicate records with the
lowest PrisonID.
Can you help me figure this out?

Thanks.
Iram/mcp

  #2  
Old May 12th, 2010, 08:53 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default The not "Max" records

Are you saying you want to delete all records for each case EXCEPT for the one
with maximum PrisonID?

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.

The following could be slow

DELETE
FROM SomeTable
WHERE PrisonID
(SELECT MAX(PrisonID) FROM SomeTable as T
WHERE T.[Case#] = SomeTable.[Case#])

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Iram wrote:
Hello,
I have a query that finds all records with a particular "Case#". I changed
the query to do totals and grouped by Case#'s. I have another field called
"PrisonID" in which I want to see all records except for the Max (except the
highest number PrisonID). Eventually I need to change this query into a
delete query so that it automatically deletes all duplicate records with the
lowest PrisonID.
Can you help me figure this out?

Thanks.
Iram/mcp

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.