UPDATE xf_post
SET message_state = 'deleted'
WHERE message_state = 'visible'
AND username = 'old name'
AND user_id = 0;
INSERT INTO xf_deletion_log (content_type, content_id, delete_date, delete_user_id, delete_username, delete_reason)
SELECT 'post', post_id, UNIX_TIMESTAMP(), 1, 'admin', 'manually deleted via query'
FROM xf_post
WHERE message_state = 'deleted'
AND username = 'old name'
AND user_id = 0
ON DUPLICATE KEY UPDATE
content_id = VALUES(content_id);
UPDATE xf_thread
SET discussion_state = 'deleted'
WHERE discussion_state = 'visible'
AND username = 'old name'
AND user_id = 0;
INSERT INTO xf_deletion_log (content_type, content_id, delete_date, delete_user_id, delete_username, delete_reason)
SELECT 'thread', thread_id, UNIX_TIMESTAMP(), 1, 'admin', 'manually deleted via query'
FROM xf_thread
WHERE discussion_state = 'deleted'
AND username = 'old name'
AND user_id = 0
ON DUPLICATE KEY UPDATE
content_id = VALUES(content_id);