title: Mysql - calculate difference between two columns in 2 different tables and insert
body: <p>I have the following statement which need to add 1 more subquery to calculate the difference between the number of followers in the <code>tweeps</code> table and the number in the current column in the <code>ranking</code> table and insert the difference in column called <code>latest</code> in <code>ranking</code> table sure PK is screenname , </p>
  
  <p>Like number in follower coulm in tweeps table is 10 current coulmn n ranking table for the same screenname is 5 the value will be added to latest is +5</p>
  
  <pre><code>mysql_query ("
      INSERT  INTO ranking
      SELECT @rank := @rank + 1, tweeps.* FROM tweeps
      JOIN( SELECT @rank := 0 ) AS init
      ORDER BY followers DESC
      ON DUPLICATE KEY UPDATE
      ranking.ranking = @rank, 
      ranking.name = tweeps.name,
      ranking.followers = tweeps.followers,
      ranking.tweets = tweeps.tweets,
      ranking.location = tweeps.location,
      ranking.`join date` = tweeps.join_date,
      ranking.avatar = tweeps.avatar;");
  mysql_close($con);
  </code></pre>