LEFT JOIN (select patent_no,legal_flag from t_legal_status as b where not exists(select 1 from t_legal_status where patent_no= b.patent_noand b.publication_date<publication_date )) h on `a`.`patent_no` = `h`.`patent_no`