M
Maxie
I've got two versions of a nested query that do the same
thing. However, one gives me an answer instantaneously and
the other takes 11 seconds. Could someone please walk me
through in detail what it is that makes the slow one take
so much longer? (I'm trying to learn these nuances so that
I can design better queries in the future.)
FAST QUERY
------------
SELECT thedate, ticker, close
FROM pub_price_history
WHERE thedate in (SELECT max(thedate) FROM pub_price_hist);
SLOW QUERY
-----------
SELECT ticker, thedate, close
FROM pub_price_hist
WHERE thedate in (SELECT DISTINCT TOP 1 thedate from
pub_price_hist ORDER BY thedate DESC);
As you can see, the only difference is how the subquery is
structured.
Thanks in advance.
Maxie
thing. However, one gives me an answer instantaneously and
the other takes 11 seconds. Could someone please walk me
through in detail what it is that makes the slow one take
so much longer? (I'm trying to learn these nuances so that
I can design better queries in the future.)
FAST QUERY
------------
SELECT thedate, ticker, close
FROM pub_price_history
WHERE thedate in (SELECT max(thedate) FROM pub_price_hist);
SLOW QUERY
-----------
SELECT ticker, thedate, close
FROM pub_price_hist
WHERE thedate in (SELECT DISTINCT TOP 1 thedate from
pub_price_hist ORDER BY thedate DESC);
As you can see, the only difference is how the subquery is
structured.
Thanks in advance.
Maxie