I use an SQL statement to remove records that exist on another database but this takes a very long time.
Is there any other alternative to the code below that can be faster? Database is Access.
email_DB.mdb is from where I want to remove the email addresses that exist on the other database (table Newsletter_Subscribers) customers.mdb is the other database (table Customers)
SQLRemoveDupes = 'DELETE FROM Newsletter_Subscribers WHERE EXISTS (select * from [' & strDBPath & 'Customers].Customers ' _ & 'where Subscriber_Email = Email or Subscriber_Email = EmailO)' NewsletterConn = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=' & strDBPath & 'email_DB.mdb' Set MM_editCmd = Server.CreateObject('ADODB.Command') MM_editCmd.ActiveConnection = NewsletterConn MM_editCmd.CommandText = SQLRemoveDupes MM_editCmd.Execute MM_editCmd.ActiveConnection.Close Set MM_editCmd = Nothing
EDIT: Tried the SQL below from one of the answers but I keep getting an error when running it:
SQL: DELETE FROM Newsletter_Subscribers WHERE CustID IN (select CustID from [‘ & strDBPath & ‘Customers].Customers where Subscriber_Email = Email or Subscriber_Email = EmailO)
I get a ‘Too few parameters. Expected 1.’ error message on the Execute line.
I would use WHERE Subscriber_Email IN (Email, Email0) as the WHERE clause
I have found from experience that using an OR predicate in a WHERE clause can be detrimental in terms of performance because SQL will have to evaluate each clause separately, and it might decide to ignore indexes and use a table scan. Sometime it can be better to split it into two separate statements. (I have to admit I am thinking in terms of SQL Server here, but the same may apply to Access)