简体   繁体   中英

Update Table Based on Existing ID with Inner Join & Update

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM