Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Max value

Status
Not open for further replies.

Trudye

Programmer
Sep 4, 2001
932
0
0
US
Hi Guys, I am trying to add a Delete statement to this query to Delete all dupes based on MAX(tblOdomStatement.fldDateStamp.

I cannot get an adequate response. Any ideas?

SELECT tblOdomStatement.fldVin, tblOdomStatement.fldLeaseNum, tblOdomStatement.fldDateStamp, tblOdomStatement.fldCustomerSign, tblOdomStatement.fldDealerSign, tblOdomStatement.fldGroundDate
FROM tblOdomStatement
WHERE (((tblOdomStatement.fldVin) In (SELECT [fldVin] FROM [tblOdomStatement] As Tmp GROUP BY [fldVin],[fldLeaseNum] HAVING Count(*)>1 And [fldLeaseNum] = [tblOdomStatement].[fldLeaseNum])))
ORDER BY tblOdomStatement.fldVin, tblOdomStatement.fldLeaseNum;

Thanx
Trudye
 
I would do a count on an entire record then insert the entire record into a new table without the count field. This would then be your new table.

You could then delete, preferably rename, your table with dups. and rename your new table to that. overhead but it is safer.

since we are in the access forum, i guess you are using ms access. create a macro to control this process.

If you enter a delete statement you will delete all the records not just the extra records.

Hope this helps
ronze
 
Ok I decided to do it on two passes. However I am having trouble with the delete. I am getting the msg the a simicolon is missing. I tried rearranging the parens but to no avail.

Here is my code:
DELETE *
FROM _sig_tblOdomStmnt
WHERE (([_sig_tblOdomStmnt].fldVin) In (SELECT [fldVin] FROM [_sig_tblOdomStmnt] As Tmp GROUP BY [fldVin],[LeaseNum] HAVING Count(*)>1 And [LeaseNum] = [_sig_tblOdomStmnt].[LeaseNum])
ORDER BY [_sig_tblOdomStmnt].fldVin, [_sig_tblOdomStmnt].LeaseNum);

Thanx
Trudye
 
your brackets are wrong...

--------------------
Procrastinate Now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top