The first query to join the parent and child, without custom_data_organization, but using the implied hierarchy:
SELECT parent.id, child.id FROM custom_def_organizations AS parent JOIN custom_def_organizations AS child ON (child.parent_id = parent.id);
This will return:
18 19 18 20 18 21 18 22 18 23
Now, to get other information:
SELECT parent.id, child.id, CONCAT(parent.title, ' - ', child.title) AS title FROM custom_def_organizations AS parent JOIN custom_def_organizations AS child ON (child.parent_id = parent.id);
This will return:
18 19 Server Support - Yes 18 20 Server Support - Site Visits Chargeable 18 21 Server Support - Site Visits Included 18 22 ... 18 23
Same concept, but with custom_data_organizations governing JOIN:
SELECT cdo.id, CONCAT(parent.title, ' - ', child.title) AS title FROM custom_data_organizations AS cdo JOIN custom_def_organizations AS parent ON (cdo.root_field_id = parent.id) JOIN custom_def_organizations AS child ON (cdo.field_id = child.id);
This will return:
85 Server Support - Site Visits Chargeable ...
source share