[DB-SIG] How can I retrieve single records in a specific order?

Casey Bralla Casey at nerdworld.org
Fri Nov 19 23:46:07 CET 2004


I'm writing a python application which will retrieve thousands of records from 
a MySQL database.  I'm having trouble getting sequential records in the order 
I want, and was hoping someone could offer suggestions of how to proceed.

Here is the python code I've gotten so far....

Database=MySQLdb.connect(db = Database, user = DatabaseUser, passwd = 
DatabasePassword, host = localhost)
DatabaseCursor = Database.cursor()
DatabaseCursor.execute("SELECT * FROM table1 ORDER BY field1")
RecordData = DatabaseCursor.fetchone()


You MySQL gurus can probably spot that I will receive a single record into 
"RecordData", and every time I run the routine, I will get the exact same 
record (in this case, the first record in the database table1 that is sorted 
by field1.)

My Question:  But how can I get a single record in this sort order, and then 
retrieve the next record in this same sort order?


TIA!
-- 

Casey Bralla
Chief Nerd in Residence
The NerdWorld Organisation


More information about the DB-SIG mailing list