how do retrieve the last record if its id or other fields are unknown...or simply i need to move the record pointer to the last record in a table...thanx a lot...

SELECT * from stud_infos WHERE stud_id = 'HOW DO I DO IT?'

Recommended Answers

All 6 Replies

Let me understand first what exactly you mean by last record.

Last as per what ?

Probably last inserted record. If you do SELECT * FROM stud_infos then the natural order is returned. The last record in your result set will be the one you need. Since you have no information about a PK field, there is no way to limit or reverse the query so it just returns your required record.

last record means, i just want to bring the record pointer to the end of file so that i can extract the record that is last inserted...the problem is the last record is unknown...(i want to perform an sql command the is similar to the .movelast command in visual basic)...simply moving the record pointer the last record in the table...
ex...my primary key is stud_id...

records in the table stud_infos
MCC-11-12-0001
MCC-11-12-0002
MCC-11-12-0003
MCC-11-12-0004
MCC-11-12-0005
MCC-11-12-0006
MCC-11-12-0007


The last record here is MCC-11-12-0007 but the scenario is i dont have idea whatever is the value of this last record since the last record will change if their are new insertion or deletion of records. this MCC-11-12-0007 is the last record...so i have to bring the record pointer this record so that i can extract the stud_id MCC-11-12-0007.... thanks a lot..po.:)

If this is an auto generated number then the following will work:

SELECT * FROM stud_infos ORDER BY stud_id DESC LIMIT 1

If you want the last inserted record, you have to store the insert time with the records.

It is always not true that the last record is the one inserted in the end.

In a typical OLTP environment one is never sure of the last record without capturing the transaction time.

ok ill try to insert the time and the date of insertion of the record...thanks...im not using autoincrement...or autogenration of id no....but thanks...i can use it in some of my modules..:)...i ll just post any update of my work thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.