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

Delete from Nested Select

Status
Not open for further replies.

jnavarro

Programmer
Dec 1, 2003
89
US
Can anyone help me. I cannot get this sql statment to excute. What I am trying to do is select record from record set and delete those records in the table


DELETE tblAI
FROM tblAI
WHERE(SELECT Div, Account, CorrespondType, COUNT (Account) AS Inquiries, MAX(MediaDate) AS MediaDate
FROM tblAI
WHERE DateResolve IS NULL
GROUP BY Div, Account, CorrespondType
HAVING COUNT(Account) > 1) DupAccount INNER JOIN tblAI ON tblAI.Div = DupAccount.Div AND tblAI.Account = DupAccount.Account AND tblAI.MediaDate = DupAccount.MediaDate AND
tblAI.CorrespondType = DupAccount.CorrespondType eneral_CP1_CI_AS = tblAI.CorrespondType


Thanks
 
Try this:
Code:
DELETE 	tblAI
FROM 	tblAI,
	(SELECT 	Div, 
			Account, 
			CorrespondType, 
			MAX(MediaDate) AS MediaDate
         FROM   	tblAI
      	 WHERE  	DateResolve IS NULL
      	 GROUP BY 	Div, Account, CorrespondType
      	 HAVING 	COUNT(Account) > 1) DupAccount
where    tblAI.Div = DupAccount.Div 
	 AND tblAI.Account = DupAccount.Account 
         AND tblAI.MediaDate = DupAccount.MediaDate 
	 AND tblAI.CorrespondType = DupAccount.CorrespondType

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top