title: Insert into a table, if there is no such rows
body: <p>I have a sessions table with the 'userid' and 'expired' columns. I want to check, whether any row with the given user ID and not expired exists and insert a new row, if no rows found.</p>
  
  <p>I've read about INSERT IGNORE, but (userid + expired) cannot be a key, since it's possible to have multiple rows with the same users (all expired), I cannot only have more than 1 not expired user.</p>
  
  <p>I tried this, but to no avail ('You have an error...'):</p>
  
  <pre><code>IF (SELECT 1 FROM sessions WHERE user = :user AND expired = 0) &lt;&gt; 1
  INSERT INTO sessions (user) VALUES(:user)
  </code></pre>
  
  <p>('expired' is 0 by default). mySQL version is 5.</p>
  
  <p><strong>UPDATE</strong>.</p>
  
  <p>I've tried this as well:</p>
  
  <pre><code>IF NOT EXISTS(SELECT 1 FROM sessions WHERE user = 0 AND expired = 0)
      INSERT INTO sessions (user) VALUES(0)
  </code></pre>
  
  <p>using HeidySQL 7. It doesn't work neither. mySQL version is 5.5.</p>
  
  <p><strong>UPDATE2</strong>. Logical errors in my statement fixed.</p>
  
  <p>Regards,</p>