Skip to content

Instantly share code, notes, and snippets.

@kitzberger
Created November 9, 2020 20:00
Show Gist options
  • Save kitzberger/da147ffdeb2083829e95ea7a099ae267 to your computer and use it in GitHub Desktop.
Save kitzberger/da147ffdeb2083829e95ea7a099ae267 to your computer and use it in GitHub Desktop.
Update SQL table with count of child elements
-- Updates tt_content.tx_mask_items with the number of child elements that refer to this record.
UPDATE tt_content parent
INNER JOIN (SELECT count(*) as count, tx_mask_items_parent FROM tt_content GROUP BY tx_mask_items_parent) children
ON children.tx_mask_items_parent = parent.uid AND parent.CType = 'mask_accordion'
SET parent.tx_mask_items=children.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment