I would like to have a trigger to perform following operation for inserted records:
# pseudocode if new.group_id is null set new.group_id = new.id els
This trigger should do what you asked.
CREATE TRIGGER mytrigger BEFORE INSERT ON mytable IF new.group_id IS NULL SET new.group_id = new.id END IF END;
It's copied from a very similar example in the MYSQL documentation page.