Search code examples
mysqlwordpressxampp

Unknown column '"' in 'where clause [MySQL]


I am getting this error Erreur SQL (1054) : Unknown column 'pk.post_id' in 'where clause' when I try to execute this query.

UPDATE `wp_posts` as pm  
SET pm.post_content = 
   (select meta_value from `wp_postmeta` as pk where pk.post_id = pm.id and pk.meta_key = "_job_description") 
 WHERE  pm.id = pk.post_id;

I didn't find out how to fix it. Can you help me with that?


Solution

  • You must use multiple-table UPDATE syntax:

    UPDATE `wp_posts` as pm  
    JOIN `wp_postmeta` as pk ON pm.id = pk.post_id 
                            AND pk.meta_key = '_job_description'
    SET pm.post_content = pk.meta_value;
    

    See https://dev.mysql.com/doc/refman/8.0/en/update.html