> Ok my gut would say that this would not give the result I want
> unless the id's are sorted by last name, and given inserts and
> such I can see that would not be the case.   But I sense the
> glimmer of an approach in this query...

You're right, I don't know why I thought you wanted to sort by ID.  Guess I
need more coffee.

I think I understand what you're trying to do:

 - Run program, fetches a name.  Processes and exits.
 - Run program again, same SQL but gets the NEXT name.  Processes and exits.

LIMIT would work, but you would need to pass the current offset to the next
instance of your code.  Of course, that counter would need to be reset
should the table data change at all and it would be an ugly hack regardless.
Forget about it.

What you're really looking for is a method to maintain state between DB
connections.  Unfortunately, no RDBMS that I can think of supports this
internally.

I think the best solution for you is to add another column to the table and
use that for a "skip" flag.

Your SQL is this:

SELECT id,first,last FROM name WHERE skip=0 ORDER BY last LIMIT 1;
UPDATE name SET skip=1 where id=<ID You just received>;

If your skip flag defaults to 0 (false) then new entries will not require a
reset.  Once you've exhausted the table (everyone has a skip of 1 (true))
you can set them all to 0 and start over again at the top.

I don't think this would be very elegant but it would do the job.  A trigger
would be handy here. <Ducks>

Adam Erickson


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to