0

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?'

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by lloydsbackyard
0

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.

0

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.:)

0

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

SELECT * FROM stud_infos ORDER BY stud_id DESC LIMIT 1
0

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.

0

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.