title: SQL Left Join. Taking too long.
body: <p>Okay so here are my table schemas.<br>
  I have 2 tables. Say Table A and Table B. The primary key of Table A is PriKeyA bigint(50) and primary key of Table B is PriKeyB varchar(255). Both PriKeyA and PriKeyB contain the same type of data.<br>
  The relevant fields of Table A required for this problem are Last_login_date_in_A (date) and Table B is the primary key itself.<br>
  What I need to do is, get those PriKeyA's in A which are not there in Table B's PriKeyB column and the Last_login_date_in_A column should be greater than 30 days from the current date. Basically I need the difference of Table A and Table B along with a certain condition(which is the date in this problem)<br>
  Here is my SQL command  </p>
  
  <pre><code>: SELECT A.PriKeyA from A  
   LEFT JOIN B ON A.PriKeyA = B.PriKeyB   
   WHERE B.PriKeyB IS NULL and DATEDIFF(CURRENTDATE,Last_login_date_in_A)&gt;30;
  </code></pre>
  
  <p>However when I run this MySQL command, it takes about ridiculously long amount of time (About 3 hours). The size of Table A is 2,50,000 and Table B is 42,000 records respectively. I thought that this problem could arise due to the fact that PriKeyA and PriKeyB are different datatypes. So i also used the <code>CAST(PriKeyB as unsigned)</code> in the query. But that too didn't work. There was a marginal performance improvement.  </p>
  
  <p>What could be the possible problems? I've used Left Joins before and they never have taken this long.</p>