0

I'm trying to pull data from an existing table (wp_postmeta) and insert the meta_value into the new table (cigar_flavor_scoring). The data should be based on the post_id and I only want to pull in data from the wp_postmeta table with a meta_key of 'caramel'. I want to then take that value and insert it into the cigar_flavor_scoring table, column caramel.

I feel like I'm very close.

 SELECT meta_value
    FROM wp_postmeta
    UPDATE cigar_flavor_scoring
    INNER JOIN cigar_flavor_scoring ON (wp_postmeta.post_id = cigar_flavor_scoring.post_id)
    WHERE meta_key = "caramel"
    SET cigar_flavor_scoring.caramel = wp_postmeta.meta_value
user2778412
  • 11
  • 1
  • 3
  • 1
    Are you trying to _insert_ new data into `cigar_flavor_scoring` or are you trying to _update_ already existing records in this table? – Tim Biegeleisen Apr 28 '17 at 03:56
  • I'm not feeling it. – Strawberry Apr 28 '17 at 07:32
  • @TimBiegeleisen Well the rows are already there with the post_id number column, not the rest of the columns are blank. So I'm assuming I am updating vs inserting. – user2778412 Apr 30 '17 at 01:45
  • Well I figured this it out and it worked: `UPDATE cigar_flavor_scoring AS cfs INNER JOIN wp_postmeta AS wpm ON (wpm.post_id = cfs.post_id) SET cfs.woody = wpm.meta_value WHERE meta_key = "woody"` – user2778412 Apr 30 '17 at 02:13

1 Answers1

-1

I guess you are looking to update a table using INNER JOIN.

Please check this thread - SQL Server - inner join when updating

Community
  • 1
  • 1
murtazat
  • 399
  • 3
  • 12
  • Why was this answer downvoted? The person who asked the question did comment that he/she finally ended up using UPDATE with INNER JOIN. Did not this answer provide the direction? – murtazat May 08 '17 at 00:15