Unable to commit query SELECT m.*,mc.*,gs.description AS subGroupDescription, if(gs.parentSubGroup,(SELECT gs2.order_by FROM group_subs AS gs2 WHERE gs2.id=gs.parentSubGroup),gs.order_by) AS orderBy, if(gs.parentSubGroup,gs.order_by+1,0) AS subOrder FROM members AS m, members_c AS mc, groups AS g, group_subs AS gs, member2group_subs AS mgs WHERE m.record_number=mc.id_c AND mgs.member_id=m.record_number AND mgs.groupSubId=gs.id AND gs.parentGroup=g.id AND g.name='Board of Directors' ORDER BY orderBy,subOrder,m.lname