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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -