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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete dup lot numbers unless qty is different

Status
Not open for further replies.

rwn

Technical User
Dec 14, 2002
420
US
I have a query that deletes the most recent duplicate entry of a lot number for a table within a specific timeframe. I would like to modify the delete query so it still deletes the most recent entry of a duplicate, but ONLY if the lab table.qty is an exact match. So if a lot number is entered twice and a qty of 100 exists and 200 exists, for the same lot number, then no delete is perform. Any suggestions??


sSQL = "DELETE [Lab Table].TDate, [Lab Table].ID, * FROM [Lab Table] WHERE ((([Lab Table].TDate) Between Date()-5 And Date())" & _
" AND (([Lab Table].ID) Not In (SELECT Min(ID) as MinID FROM [Lab Table] WHERE ([Lab Table].TDate Between Date()-5 " & _
"And Date()) GROUP BY [Lab Table].LotNumber)));
 
use a subquery?

delete * from tbl where somecondition AND (
select qty from tbl2 where someCondition
) = tbl.qty

--------------------
Procrastinate Now!
 
the sub query will run after the main delete query, so all dup will be gone already.
 
I added the code qty<>qty, but now no duplicates are deleted.

sSQL = "DELETE [Lab Table].TDate, [Lab Table].ID, * FROM [Lab Table] WHERE ((([Lab Table].TDate) Between Date()-5 And Date())" & _
" AND ([Lab Table].Qty <> [Lab Table].Qty)" & _
" AND (([Lab Table].ID) Not In (SELECT Min(ID) as MinID FROM [Lab Table] WHERE ([Lab Table].TDate Between Date()-5 " & _
"And Date()) GROUP BY [Lab Table].LotNumber)));"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top