title: Trigger update the same table with data from another table after insert
body: <p>I have two unrelated tables tbl_A &amp; tbl_B</p>
  
  <p>tbl_A</p>
  
  <pre><code>+----+---------------------+------+
  | id | url                 | slug |
  +----+---------------------+------+
  |  1 | http://example.com/ | 3qqd |           
  |  2 | http://example.com/ | t8af |           
  |  3 | http://example.com/ | sjim |           
  |  4 | http://example.com/ | awfo |           
  |  5 | http://example.com/ | 6myy |           
  +----+---------------------+------+
  </code></pre>
  
  <p>tbl_A description: </p>
  
  <pre><code>+---------------------+---------------------+------+-----+---------------------+----------------+
  | Field               | Type                | Null | Key | Default             | Extra          |
  +---------------------+---------------------+------+-----+---------------------+----------------+
  | id                  | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
  | url                 | text                | YES  |     | NULL                |                |
  | slug                | varchar(255)        | YES  | MUL | NULL                |                |
  +---------------------+---------------------+------+-----+---------------------+----------------+
  </code></pre>
  
  <p>and another table :</p>
  
  <p>tbl_B</p>
  
  <pre><code>+----+---------------------+---------------------+------+           
  | ID | user_name           | url                 | slug |
  +----+---------------------+---------------------+------+
  |  1 | john.reese          | NULL                | NULL |       
  +----+---------------------+---------------------+------+
  </code></pre>
  
  <p>tbl_B description : </p>
  
  <pre><code>+---------------------+---------------------+------+-----+---------------------+----------------+
  | Field               | Type                | Null | Key | Default             | Extra          |
  +---------------------+---------------------+------+-----+---------------------+----------------+
  | ID                  | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
  | user_name           | varchar(60)         | NO   | MUL |                     |                |
  | url                 | text                | YES  |     | NULL                |                |
  | slug                | varchar(255)        | YES  | MUL | NULL                |                |
  +---------------------+---------------------+------+-----+---------------------+----------------+
  </code></pre>
  
  <p>tbl_A.id is unrelated to tbl_B.ID. </p>
  
  <p>tbl_B.ID is userID field and gets filled up dnamically when a new user registers. So that tbl_B.ID gets a row inserted automatically as a user register, tbl_B.ID value gets auto incremented.</p>
  
  <p>tbl_A on the other hand already exists with all the details.</p>
  
  <blockquote>
    <p>What I want to achieve: whenever a new user registers and userID is
    INSERT into tbl_B.ID, at the same time it should trigger an update of
    tbl_B.user and tbl_B.slug with the values taken from tbl_A.user and
    tbl_A.slug.</p>
  </blockquote>
  
  <p><strong>Outcome</strong>: After ID 1 is added</p>
  
  <pre><code>+----+---------------------+---------------------+------+           
  | ID | user_name           | url                 | slug |
  +----+---------------------+---------------------+------+
  |  1 | john.reese          | http://example.com/ | 3qqd |       
  +----+---------------------+---------------------+------+
  </code></pre>
  
  <p>Hope I am able to explain. I was trying to use triggers but got lost, am a newbie with mysql, please bear with me.</p>
  
  <pre><code>drop trigger if exists bi_tbl_B $$
  delimiter $$
  
  create trigger bi_tbl_B before insert on tbl_B
  for each row begin
     UPDATE tbl_B
       SET url = url +
         (SELECT url
            FROM tbl_A
            WHERE id = NEW.id)
      WHERE ID = NEW.ID;
  
  end;
  $$
  
  delimiter ; 
  </code></pre>
  
  <p>I don't know whether this is even possible or should I try the other way round.</p>
  
  <p>Add a field <code>user_id</code> in tbl_A and <code>AFTER INSERT</code> on tbl_B update tabl_A.user_id column with the userID from tbl_B.ID</p>
  
  <p>I am open to suggestions, if not trigger then procedures. </p>