title: SQL Server insert if not exists best practice [EXTENDED]
body: <pre><code>INSERT `locality` (province_id)
  SELECT DISTINCT `province_id`
  FROM `locality` localreturn
  WHERE
     NOT EXISTS (SELECT * FROM `locality` local
                WHERE localreturn.province_id = local.province_id)
  </code></pre>
  
  <p><strong>If the query tested passes how do i insert a value?</strong>
   a normal insert would be like:</p>
  
  <pre><code>INSERT INTO `locality` (`province_id`) VALUES (1919)
  </code></pre>
  
  <p>Leeched Source:
  <a href="https://stackoverflow.com/questions/5288283/sql-server-insert-if-not-exists-best-practice">SQL Server insert if not exists best practice</a></p>