strago Posted April 28, 2010 Share Posted April 28, 2010 Datebase: blog Table: nitendoposts <?php function clearDuplicatePosts(){ global $wpdb; $wpdb->query(" delete bad_rows.* from $wpdb->nitendoposts as bad_rows inner join ( select post_title, MIN(id) as min_id from $wpdb->nitendoposts group by post_title having count(*) > 1 ) as good_rows on good_rows.post_title = bad_rows.post_title and good_rows.min_id <> bad_rows.id; "); } add_action('publish_post', 'clearDuplicatePosts'); ?> Does nothing. When I try to run it from phpMyAdmin using DELETE bad_rows . * FROM nitendoposts AS bad_rows INNER JOIN ( SELECT post_title, MIN( id ) AS min_id FROM nitendoposts GROUP BY post_title HAVING count( * ) >1 ) AS good_rows ON good_rows.post_title = bad_rows.post_title AND good_rows.min_id <> bad_rows.id I get #1064 - 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 'SELECT post_title, MIN( id ) AS min_id FROM nitendoposts GROU How do you get the script to remove duplicates by searching through the 'post_title' field? Quote Link to comment https://forums.phpfreaks.com/topic/200070-1064-you-have-an-error-in-your-sql-syntax-deleting-duplicates/ Share on other sites More sharing options...
fenway Posted April 28, 2010 Share Posted April 28, 2010 And the query version of this statement works? Quote Link to comment https://forums.phpfreaks.com/topic/200070-1064-you-have-an-error-in-your-sql-syntax-deleting-duplicates/#findComment-1050143 Share on other sites More sharing options...
strago Posted April 28, 2010 Author Share Posted April 28, 2010 That's the full script. It's a word press add-on. Quote Link to comment https://forums.phpfreaks.com/topic/200070-1064-you-have-an-error-in-your-sql-syntax-deleting-duplicates/#findComment-1050215 Share on other sites More sharing options...
strago Posted April 29, 2010 Author Share Posted April 29, 2010 <?php /* Plugin Name: Duplicate Posts Eraser */ function simpleDuplicatePosts(){ global $wpdb; $wpdb->query(" delete from posts USING posts, posts as vtable WHERE (posts.ID > vtable.ID) AND (posts.post_title=vtable.post_title) "); } add_action('publish_post', 'simpleDuplicatePosts'); ?> works...if you don't have a table prefix. From the config.php file.... $table_prefix = 'WHATEVER'; How do you make this script check for a $table_prefix like WHATEVERposts? Quote Link to comment https://forums.phpfreaks.com/topic/200070-1064-you-have-an-error-in-your-sql-syntax-deleting-duplicates/#findComment-1050299 Share on other sites More sharing options...
fenway Posted April 30, 2010 Share Posted April 30, 2010 That's the full script. It's a word press add-on. So you didn't write it? Quote Link to comment https://forums.phpfreaks.com/topic/200070-1064-you-have-an-error-in-your-sql-syntax-deleting-duplicates/#findComment-1051194 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.