September 5th, 2005, 7:24 am
QuoteOriginally posted by: AlphaNumericusQuoteOriginally posted by: RussellI wonder if internally the server just does one table scan?No, I don't know of any server that would be smart enough to do this in one scan. I bet it does 4 scans - one to find the min in the subquery, one to find the max, one to match the min, and one to match the max.If you can use cursors, then you can write your own logic to do this with one full scan.But would the hassle involved in replacing one SQL statement with something cursor-based be worth it? And is it really faster than a SQL query on an appropriately indexed table?Also, I think saliq's version could be simplified toselect Time,bidPrice,askpricefrom Tabwhere bidprice = (select Max(bidprice) from tab) OR askprice = (select Min(askprice) from tab);
Last edited by
ZmeiGorynych on September 4th, 2005, 10:00 pm, edited 1 time in total.