0

I'm trying to run this sql query and keeps getting this error:

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 'INNER JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID WHERE wp_posts.post_typ' at line 3 (Line 4)

My sql query is this:

UPDATE wp_postmeta
SET meta_value = "1316"
INNER JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID
WHERE wp_posts.post_type="imagen_dia" AND wp_postmeta.meta_key="ae_post_template"

Any help please?

3
  • 1
    Missing FROM... Commented Nov 20, 2017 at 20:09
  • Which DBMS? Oracle? MySQL? SQL Server? ... The syntax for joined updates differs a lot in the various DBMS. Double quotes are for names by the way; use single quotes for strings. Commented Nov 20, 2017 at 20:11
  • 1
    Possible duplicate of MYSQL Update Statement Inner Join Tables Commented Nov 20, 2017 at 20:13

3 Answers 3

2

In mysql the JOIN should be before the set

UPDATE wp_postmeta
INNER JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID
SET meta_value = "1316"
WHERE wp_posts.post_type="imagen_dia" AND wp_postmeta.meta_key="ae_post_template"
Sign up to request clarification or add additional context in comments.

1 Comment

THANKS A LOT!!! Now it works perfectly!! I was using sql all the time not knowing I have to use mysql. You saved my day. Thanks again my friend!! :)
1

The syntax for joined updates is vendor-specific. So do this without a join to have the update statement simple, readable and safe :-)

UPDATE wp_postmeta 
SET meta_value = '1316'
WHERE meta_key = 'ae_post_template'
AND post_id IN (SELECT id FROM wp_posts WHERE post_type = 'imagen_dia');

This statement is standard SQL and should work in about every RDBMS.

Comments

0

You are missing the FROM word:

UPDATE wp_postmeta
SET meta_value = "1316"
FROM wp_postmeta
INNER JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID
WHERE wp_posts.post_type="imagen_dia" AND wp_postmeta.meta_key="ae_post_template"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.