title: MYSQL : How to insert multiple value in a single column using array and only if not exist
body: <p>I have a site where I want to add songs with all details like <code>Artist</code> ,<code>Label</code> etc. I upload song using <code>addfile.php</code> file. This page have individual text input fields and form POST to <code>addfile_db.php</code> where I have some <code>SQL</code> Query. 
  Query for insert into file. Works ok. Dont want any changes.</p>
  
  <pre><code> $qryUpdate = "insert into file
   (name,artist,music,label,lyrics, recommended,dname,cid,ext,thumbext,size,`desc`,newtag,date,imagetype) 
  VALUES 
   ('$name','$artist','$music','$label','$lyrics','$recommended','$newname',$cid,'$ext','$thumbext','$fileSize','$des','$newtag','(now())',0)";
  $db-&gt;query($qryUpdate);
  </code></pre>
  
  <p>I also want to insert <code>$artist</code> value into <code>artist</code> table. A single song may multiple artist. <code>$artist</code> have comma seperated value like this  <code>Artist1,Artist2,Artist3</code> and I explode values into array.</p>
  
  <pre><code>$artist_array = explode(","$artist); 
  </code></pre>
  
  <p>I try this query.</p>
  
  <pre><code>   $ArtQry = "insert  into artist (name) VALUES ('" . implode("'), ('", $artist_array) . "')";
    $db-&gt;query($ArtQry);
  </code></pre>
  
  <p>Above codes works perfectly. Adds 3 rows to table <code>artist</code> with unique id lke 1,2,3,4 .... </p>
  
  <p>Problem is this that I want to insert into <code>artist</code> if already not exist.
  I have tried this code but not works, inserts nothing when I use these code.</p>
  
  <pre><code>INSERT INTO artist (name)
  SELECT * FROM (SELECT '" . implode("', '", $artist_array) . "') AS tmp
  WHERE NOT EXISTS (
  SELECT name FROM artist WHERE name = '" . implode("'), ('", $artist_array) . "')";
  ) LIMIT 1;
  </code></pre>