I have the following table test
test
iD Name ParentId GroupID ----------------------------- 1 1 Null 2 1 Null 3
UPDATE test SET GroupID = 1 WHERE ParentId = 1 UPDATE test SET GroupID = 2 WHERE ParentId = 7 UPDATE test SET GroupID = 3 WHERE ParentId = 9