Skip to content

Instantly share code, notes, and snippets.

@joshuabaker
Created August 18, 2016 13:38
Show Gist options
  • Save joshuabaker/2c67366f14a32718015201a41fe5cbc9 to your computer and use it in GitHub Desktop.
Save joshuabaker/2c67366f14a32718015201a41fe5cbc9 to your computer and use it in GitHub Desktop.
Appends “ (duplicate)” to any duplicate tags within a Craft CMS database. Assumes table prefix is `craft_`.
UPDATE craft_content
SET craft_content.title = CONCAT(craft_content.title, ' (duplicate)')
WHERE craft_content.elementId IN (
SELECT tmp.elementId
FROM (
SELECT *
FROM craft_content
) AS tmp
JOIN craft_tags ON craft_tags.id = tmp.elementId
GROUP BY tmp.title
HAVING COUNT(*) > 1
)
@joshuabaker
Copy link
Author

Needs to be limited to specific tag groups via a second JOIN within the sub-query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment