title: SQL check if existing row, if not insert and return it
body: <p>I'm having a problem with my sql query. I need to insert a data that needs to be checked first if it is existing or not. If the data is existing the sql query must return it, if not insert and return it. I already google it but the result is not quite suitable to my problem. I already read this.</p>
  
  <p><a href="https://stackoverflow.com/questions/639854/check-if-a-row-exists-otherwise-insert">Check if a row exists, otherwise insert</a>
  <a href="https://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql">How to &#39;insert if not exists&#39; in MySQL?</a></p>
  
  <p>Here is a query that' I'm thinking.</p>
  
  <pre><code>INSERT INTO @tablename(@field, @conditional_field, @field, @conditional_field) 
  VALUES(
  "value of field"
  (SQL QUERY THAT CHECK IF THERE IS AN EXISTING DATA, IF NOT INSERT THE DATA and RETURN IT, IF YES return it),
  "value of feild",
  (SQL QUERY THAT CHECK IF THERE IS AN EXISTING DATA, IF NOT INSERT THE DATA and RETURN IT, IF YES return it)
  );
  </code></pre>
  
  <p>Please take note that the conditional field is a required field so it can't be NULL.</p>