=====sql1===== SELECT mp_player_id AS mp_pl_id ,mp_sts,mp_notes,mp_class ,su_score,su_to_par,su_rank ,su_rank_code,su_sts ,su_new_total ,su_hdcp,su_net ,CASE WHEN su_rank is null THEN 0 ELSE 1 END AS is_null ,gm.`name` ,gm.id FROM match_player LEFT JOIN player_summary ON mp_player_id = su_pl_id AND mp_match = su_mt_id AND su_rd_id = '' LEFT JOIN gp_manage gm ON gm.id = mp_class WHERE mp_match = '' AND mp_notes not in ('R1','R2','R3','R4') ORDER BY mp_class ASC,is_null DESC, su_rank, su_pl_id =====sql2===== SELECT mp_player_id AS mp_pl_id, mp_sts, mp_notes, su_score, su_to_par, su_rank, su_rank_code, su_sts,su_new_total,su_hdcp,su_net FROM match_player LEFT JOIN player_summary ON mp_player_id = su_pl_id AND mp_match = su_mt_id AND su_rd_id = '' WHERE mp_match = '' ORDER BY mp_sts,su_rank, su_pl_id