virtualphoenix Posted April 4, 2011 Share Posted April 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232647-sql-query-to-remove-content-in-a-field-from-one-particular-point-on/ Share on other sites More sharing options...
kickstart Posted April 4, 2011 Share Posted April 4, 2011 Hi Should be able to use substr / left and instr. SELECT LEFT(somefield, INSTR(somefield,'More Useful Tips') -1) FROM sometable All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/232647-sql-query-to-remove-content-in-a-field-from-one-particular-point-on/#findComment-1196614 Share on other sites More sharing options...
virtualphoenix Posted April 4, 2011 Author Share Posted April 4, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232647-sql-query-to-remove-content-in-a-field-from-one-particular-point-on/#findComment-1196728 Share on other sites More sharing options...
kickstart Posted April 4, 2011 Share Posted April 4, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232647-sql-query-to-remove-content-in-a-field-from-one-particular-point-on/#findComment-1196771 Share on other sites More sharing options...
virtualphoenix Posted April 6, 2011 Author Share Posted April 6, 2011 Tried it. It actually wiped out the entire field, and that is not what I need. Fortunately I had backed up the DB. Quote Link to comment https://forums.phpfreaks.com/topic/232647-sql-query-to-remove-content-in-a-field-from-one-particular-point-on/#findComment-1197940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.