Jump to content

SQL Query to remove content in a field from one particular point on.


Recommended Posts

Hello,

 

I'm new to the forums and certainly not experienced with SQL.

 

I have a wordpress installation and basically want to achieve the following:  I need a certain part the content within all fields that belong to the column post_content removed.

 

All these fields have, after a block a text, the phrase: More Useful Tips , after which another block of text comes up. I basically need all this last part to be removed.  Nothing else comes after, it'd be the end of the post content.

 

Example:

 

<p>First Block of Text</p>

 

More Useful Tips

<p>Last block of Text</p>

 

What I need is just the SQL query that allows me to perform this operation in all fields under the column post_content.

 

I have MySQL 5.0.

 

Should be able to use substr / left and instr.

 

SELECT LEFT(somefield, INSTR(somefield,'More Useful Tips') -1)
FROM sometable

 

 

Thanks Keith.

 

Is there anything missing?.  Since it doesn't seem to modify any of the fields, this is what I'm doing:

 

SELECT LEFT(post_content, INSTR(post_content,'More Useful Tips') -1)
FROM wp_posts

Hi

 

The code I gave was to select the rows to bring them back. You should be able to use similar syntax to update the table, but if you do this be very careful and back up the data first.

 

UPDATE wp_posts
SET post_contect = LEFT(post_content, INSTR(post_content,'More Useful Tips') -1)

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.