I found this SQL query (Magento Sort Categories Alphabetically using SQL Query) and I've been successfully using it to re-sort all of our 30000+ categories but the problem I have is that it re-sorts all categories. I only have one category that needs re-sorting every now and then so my question is, how do I modify below query so that it only sorts all subcategories for a specific category (ID: 38744)?
SET @i=0;
SET @j=0;
DROP TABLE IF EXISTS AAA_NEW_POSITION;
CREATE TABLE AAA_NEW_POSITION SELECT e.entity_id AS 'entity_id',
vn.value AS 'name',
e.position AS 'old_position',
@i:=@i + 1 AS 'new_position' FROM
catalog_category_entity e
LEFT JOIN
catalog_category_entity_varchar vn ON e.entity_id = vn.entity_id
AND vn.attribute_id = 41
ORDER BY vn.value;
ALTER TABLE AAA_NEW_POSITION ORDER BY name;
UPDATE AAA_NEW_POSITION
SET
new_position = @j:=@j + 1
ORDER BY name;
UPDATE catalog_category_entity e
LEFT JOIN
AAA_NEW_POSITION np ON e.entity_id = np.entity_id
SET
e.position = np.new_position;
DROP TABLE IF EXISTS AAA_NEW_POSITION;