title: MySQL INSERT with a SELECT based on matching column
body: <p>I am trying to populate a table's id's in one table based on some matching column in another table, here is my query:</p>
  
  <pre><code>INSERT INTO adverts (publication_id) VALUES (SELECT publications.id FROM publications WHERE publications.name LIKE CONCAT ('%', (adverts.publication), '%'));
  </code></pre>
  
  <blockquote>
    <p>1064 - 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 'SELECT publications.id FROM publications WHERE publications.name
    LIKE CONCAT ('%' at line 1</p>
  </blockquote>
  
  <p>Not sure where I am going wrong here, can anybody help?</p>
  
  <p>Below are my 2 table structures:</p>
  
  <p>Adverts table: 
  <a href="https://i.stack.imgur.com/tZ7t8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tZ7t8.png" alt="enter image description here"></a></p>
  
  <p>Publications table:
  <a href="https://i.stack.imgur.com/rFocM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rFocM.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT</strong>
  Below you can find some sample data from both tables, ideally what I am trying to achieve is to insert the <code>id</code> value from the <code>publications</code> table into the <code>publications_id</code> in the <code>adverts</code> table based on whether or not there is a match in the <code>advert.publication</code> - <code>publications.name</code> columns.</p>
  
  <p>Adverts sample data:
  <a href="https://i.stack.imgur.com/5tN2R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5tN2R.png" alt="enter image description here"></a></p>
  
  <p>Publications sample data:
  <a href="https://i.stack.imgur.com/62TZn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/62TZn.png" alt="enter image description here"></a></p>
  
  <p>Textual format of sample data:</p>
  
  <p>Adverts:</p>
  
  <pre><code>"56d4085e-654c-47e1-86f0-1e7f5850bebe",,"Saturday 27th February 2016","The Daily Telegraph","188833f6-7405-11e6-96f3-0800274f2cef","2016-09-06","pdf/1/a/1a5a83.pdf","0","2016-02-29 08:59:10","2016-09-06 08:31:50"
  "56d71a59-60cc-4a9b-9170-0eb15850bebe",,"Sunday 28th February 2016","The Scottish Sunday Mail",,"2016-02-28","jpg/a/8/a8d73b.jpg","0","2016-03-02 16:52:41","2016-03-02 16:53:13"
  "56daa0f6-a2c8-4346-ac05-6f825850bebe",,"Saturday 5th March 2016","The Daily Telegraph",,"2016-03-05","pdf/9/e/9eda94.pdf","0","2016-03-05 09:03:50","2016-03-05 09:04:59"
  "56daa30b-f8c4-40aa-8197-6f555850bebe",,"Friday 12th February 2016","Daily Star",,"2016-02-12","pdf/9/2/921346.pdf","0","2016-03-05 09:12:43","2016-03-05 09:13:26"
  "56daa37c-a46c-4446-9fa5-6f825850bebe",,"Sunday 14th February 2016","Sunday Express",,"2016-02-14","pdf/3/b/3b8fc2.pdf","0","2016-03-05 09:14:36","2016-03-05 09:14:36"
  "56daa3ee-441c-4bb0-b9ff-6f555850bebe",,"Saturday 27th February 2016","Daily Express",,"2016-02-27","pdf/e/b/ebb99b.pdf","0","2016-03-05 09:16:30","2016-03-05 09:16:30"
  "56daa44f-4124-41bd-bb34-6fb95850bebe",,"Sunday 28th February 2016","Daily Star Sunday ",,"2016-02-28","pdf/1/e/1e412d.pdf","0","2016-03-05 09:18:07","2016-03-05 09:18:07"
  </code></pre>
  
  <p>Publications:</p>
  
  <pre><code>"000f371a-7405-11e6-96f3-0800274f2cef","The Daily Telegraph","png/6/9/69e409.png","2016-09-06 00:00:00","2016-09-06 07:43:31"
  "10895d76-7405-11e6-96f3-0800274f2cef","The Scottish Sunday Mail","jpg/4/1/41b6e6.jpg","2016-09-06 00:00:00","2016-09-06 07:44:02"
  "188833f6-7405-11e6-96f3-0800274f2cef","Daily Star","png/d/c/dcb8dd.png","2016-09-06 00:00:00","2016-09-06 07:44:22"
  "212778a5-7405-11e6-96f3-0800274f2cef","Sunday Express","gif/5/2/529a66.gif","2016-09-06 00:00:00","2016-09-06 07:45:57"
  "2fa48a98-7405-11e6-96f3-0800274f2cef","Daily Express","gif/6/c/6c5be4.gif","2016-09-06 00:00:00","2016-09-06 07:46:19"
  "37d0b036-7405-11e6-96f3-0800274f2cef","Daily Star Sunday","png/c/e/ce7c42.png","2016-09-06 00:00:00","2016-09-06 07:46:44"
  "3f78db05-7405-11e6-96f3-0800274f2cef","Scottish Daily Mail","jpg/5/c/5caf2f.jpg","2016-09-06 00:00:00","2016-09-06 07:47:10"
  </code></pre>