0

I'm trying to write a basic query that changes a "post type" for any posts that contain the word "releases" in their post title.

The query I've written comes up with a syntax error, and I'm uncertain as to where I've gone wrong.

UPDATE TABLE wp_posts SET post_type = "release" WHERE post_title = "%RELEASE%"; 
1
  • 1
    In SQL double quotes are for delimited identifiers (e.g. "columnname"). Use single quotes for string literals. Also, do LIKE '%RELEASE%'. Commented Dec 15, 2015 at 8:13

2 Answers 2

1

Change your query to:

UPDATE wp_posts 
SET post_type = 'release' 
WHERE post_title LIKE '%release%'; 

The syntax error comes from the additional "TABLE" keyword, which is not required.

Sign up to request clarification or add additional context in comments.

Comments

1
UPDATE wp_posts SET post_type = 'release' WHERE CHARINDEX('RELEASE', post_title) > 0

OR

UPDATE wp_posts SET post_type = 'release' WHERE post_title LIKE '%RELEASE%'

4 Comments

Give some explanation along with your answer, it will help the OP.
Thanks for contributing - Although I must admit I already tried the answer posted before yours. So as yet, this is untested by myself.
Sorry @Haris, I'm new at this :) . The first Update's condition is using CHARINDEX(text_to_find, column_to_search_in) and it returns int (the position where it finds the text_to_find in the text from column_to_search_in). The second Update uses LIKE (when I was writing it, Radu Gheorghiu already answered.
No problem @shanDB. You will probably get the chance to use CHARINDEX in other queries.

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.