title: insert, if exist update using trigger
body: <p>I want to implement a Viewed system for my website. Here is the structure of my tables:</p>
  
  <pre><code>// table1
  id | user_or_ip | post_id | date_time   // inserting new row for each viewed
  
  // table2
  id | post_id | total_viewed             // getting the number of total viewed for each post
  </code></pre>
  
  <p>Now I need to a trigger for insert/update <code>table2</code> after insert in <code>table1</code>. </p>
  
  <p>I 
  think I have to use <code>on duplicate key</code>.</p>