Select x.ApplyID,x.ApplyCode,x.CompanyID,x.ApplyTime,y.UserID,y.Uptime,x.StatusID From otApplyView x join (select a.* from otApplyFlow a right join (select ApplyID,max(Uptime) as uptime from otApplyFlow Where StatusID = 30 group by ApplyID) b on a.uptime=b.uptime ) y on x.ApplyID= y.ApplyID Where y.UserID=2