SELECT GROUP_CONCAT(t1.id) FROM table_name as t1 left join table_name as t2 on t2.id = t1.parent_id where t1.parent_id > 0 and t2.id is null
DELETE t1 FROM table_name as t1 left join table_name as t2 on t2.id = t1.parent_id where t1.parent_id > 0 and t2.id is null
каким образом получить все записи где from или to = 1?
SELECT * FROM `name_table` WHERE `to` = '1';
SELECT * FROM `name_table` WHERE `form` = '1';
SELECT * FROM `name_table` WHERE `to` = '1' AND `form` = '1';