In article <[EMAIL PROTECTED]>, Stephen Rasku <[EMAIL PROTECTED]> writes:
>> I guess this is an oversimplification. Often you can use a single SQL set >> operation instead of a loop. Your example would probably be the same as >> >> UPDATE packet >> SET timestamp = now() >> WHERE timestamp < now() - INTERVAL 15 SECOND >> >> Maybe you should explain what you're trying to achieve, not what you >> think how to do it. > Sure. I am using MySQL to store packets for transmission. I want to > send the oldest, highest priority packets first. Once I send it, I > don't want to resend it for at least 15 seconds so I have time to wait > for an acknowlegement. Based on external events, I may exit the loop > before processing all the rows. In this case, I only want to update > the timestamp on rows that I processed. Any rows that I haven't > processed yet should keep the old timestamp. I see. Me thinks it's fundamentally unclean to iterate through a result set and changing rows while doing so. You could remember the pkeys of the rows processed and then do a single UPDATE ... WHERE pkey IN (...) after the loop, but maybe this might not be necessary at all: how about SELECTing only a single row (with LIMIT), processing that row, UPDATEing it, and all that within some loop? You're doing more SELECTs that way, but with the proper indexes this might not be a problem. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]