Remove duplicate nodes (dedupe) based on title.

Here is a function that will remove all duplicate nodes (based on title) for a certain content type. It keeps the most recent one.

<?phpfunction dedupe($type) {  $previous = array();  $result = db_query("SELECT nid, title FROM {node}     WHERE title IN       (SELECT title FROM {node}         WHERE type = '%s'         GROUP BY title HAVING count(*) > 1)     ORDER BY title, created DESC", $type);  while ($row = db_fetch_array($result)) {    if ($row['title'] == $previous['title']) {      node_delete($previous['nid']);    }    $previous = $row;  }}?>