title: MySQL syntax error regarding WHERE NOT EXISTS
body: <p>I have a Chef recipe for creating Unix user IDs and deploying them across multiple nodes, to guarantee uniqueness and prevent devs from having to track them themselves. They merely name the application and it is granted a unique ID if an ID for that application doesn't already exist. If one does, it is simply returned to the script and user accounts are created on the webservers with the appropriate value.</p>
  
  <p>I have a mysql database with a single table, called application_id_table which has two columns, id and application_name. id is autoincrementing and application name cannot be null (and must be unique).</p>
  
  <p>Removing the Ruby from my script and making a couple of substitutions, my sql looks like this:</p>
  
  <blockquote>
    <p>INSERT INTO application_id_table(application_name) VALUES('andy_test')
    WHERE NOT EXISTS (select 1 from application_id_table WHERE
    application_name = 'andy_test');</p>
  </blockquote>
  
  <p>when run, I receive the syntax parsing error:</p>
  
  <blockquote>
    <p>ERROR 1064 (42000): You have an error in your SQL syntax; check the
    manual that corresponds to your MySQL server version for the right
    syntax to use near 'WHERE NOT EXISTS (select 1 from
    application_id_table WHERE application_name = 'a'</p>
  </blockquote>
  
  <p>I recall seeing that the values statement does not allow a where clause but I don't wish to use a select statement to populate the values as I'm populating them from variables supplied from within Ruby/Chef. Anyone have an idea how to accomplish this?</p>