My goal is to create an UPDATE statement that updates parent records' default_page_id to be that of the earliest child created.
The parent/child is 2 levels max/deep limited by the UI; the parent_id column denotes the parent of the record, the type value of root further simplifies what the root/parents are.
I have a dbfiddle with a DDL/DML here: https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=994d9bf3b20b3bbab21547d4334fc0e7
Ultimately my SELECT which I am trying to get right will become my UPDATE is here but uses MIN(id) which wouldn't be feasible as id is a char(36) and thus id does not autoincrement; I have tried to use MIN(created) but am missing the necessary updates to the GROUP BY in order to solve this and would appreciate another eye!
SELECT
*
FROM
(
SELECT
test_pages.id
FROM
test_pages
WHERE
test_pages.default_page_id is null
and test_pages.type = "root"
) as a
LEFT JOIN(
SELECT
parent_id ,
MIN(id) AS id
from
test_pages
WHERE
test_pages.type = "container"
GROUP BY
parent_id
) as b ON b.parent_id = a.id