Add LIMIT x,y (x is first row and y the number of rows 1.e. 1,1 for first row) at the end of the SQL and order the SQL. Not sure if this helps, just initial thoughts.
On Wed, 2003-10-08 at 13:04, Ciprian Trofin wrote: > I have 2 tables: currencies and quotes > > currencies > ========== > id currency > ------------- > > quotes > ====== > id date id_currency value > ------------------------------- > Index (date, id_currency - UNIQUE) > > > In order to find the most recent value for a currency I use the following > logic: > > 1. SELECT max(date), id_currency FROM quotes GROUP BY id_currency > > 2. for each set of values in result: > SELECT C.currency, Q.value FROM quotes Q, currencies C > WHERE C.id = Q.id_currency AND > Q.date = $result[max_date] AND > Q.id_currency = $result[id_currency] > > The procedure is quite slow, because for the 2nd step I have nnn queries > where nnn = number of rows in the 1st step. > > Could you suggest a better and faster approach ? -- **************************************************************** * Ben Edwards Tel +44 (0)1179 553 551 ICQ 42000477 * * Homepage - nothing of interest here http://gurtlush.org.uk * * Webhosting for the masses http://www.serverone.co.uk * * Critical Site Builder http://www.criticaldistribution.com * * online collaborative web authoring content management system * * Get alt news/views films online http://www.cultureshop.org * * i-Contact Progressive Video http://www.videonetwork.org * * Fun corporate graphics http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * **************************************************************** -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]