MySQL most efficient method to find missing values from multiple tables -


I have three tables, the first is the list of email addresses:

  Addresses: Id - integer, this is the primary key & lt; Br> Apparently to get into the address desk: - Integer, foreign key reference id: addresses - sent "and" received "tables are the other columns, but they can not Not important for the sent and received tables every time an email is sent or received and if the address is not already in the "Addresses" table, then it is added.T tables can be quite large (100,000 +) . <<< p> 

"Sent" and " Entries for the "received" tables are purified on a regular basis and the entries to be removed due to various reasons, leaving the orphaned entries in the "address" table.

I clean orphaned entries in the "Addresses" table To find the most effective method in MySQL, I have a query that is yet to be done:

  Delete from addresses where id is not (choose to get rid of) and no id (Choose the sender sent);  

This works, but it can take a lot of time to run and certainly not the most effective way to do it! I also Tried to:

  Remove from the address where it is not present (from where 's' was sent, select sid = addresses.id) and does not exist (Received from LS Select 'X' where get rid of = addresses.id); It was a little faster, but still takes a lot of time, I suspect that I need to use the join syntax, but at this time my SQL knowledge has taken part in me!   

this should do the trick

  deleted ads Send.sid = adresses.id LEFT received received received.Raid = adresses.id has been sent where SID is zero and received.It is  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -