mysql - Date = max(Date) Running Slowly -
i have 6 million records in historical_data table. trying find symbols last recorded row not equal highest date on table. believe query work takes forever run. long in fact, times out connection each time. there way make query run faster?
select symbol, histdate historical_data histdate = (select max(histdate) historical_data b a.symbol = b.symbol);
you want index query. best index historical_data(symbol, histdate)
.
you might find faster phrase query as:
select hd.* historical_data hd join (select symbol, max(histdate) maxhd historical_data group symbol ) s on hd.histdate = s.histdate;
edit:
oops. sample query doesn't text says want. that:
select symbol historical_data hd cross join (select max(histdate) maxhd historical_data) m group symbol, maxhd having max(hd.histdate) <> maxhd;
Comments
Post a Comment