Jump to content

select the last register


Guest Seph

Recommended Posts

Good Monring people!I'm in a infinty looping, and to resolv this i must select only the last register of my database, ho can i do this?Thanks

Link to comment
Share on other sites

SQL = "SELECT * FROM TBL_NAMESet RS = Server.CreateObject("ADODB.Recordset")RS.Open SQL, MyConn RS.MOVELAST         'This will take you to the last record of the recordset I guess this is what you are looking for.. HTH

That's a bad way to select the last registered user, because it causes MySQL to cache all of the records in the database, when it only makes use of a single record.A better SQL statement is:
Select * From Your_TABLE ORDER BY ID Desc Limit 1

Basically, this just reverses the order the table and selects one record, its much faster, doesn't require MySQL to cache all the data in the table, and doesn't require an "RS.Movelast" line.

Link to comment
Share on other sites

What Seph wants is to select the last register, but when you order the last register may be different from the actual one. correct me if i am wrong.

It could only do that if he orders his list by something other than the unique ID of his users (such as ordering them by name).But if Seph is anything like me, he most likely has a uniqueID assigned to each record that increases by 1 for each record. Then the newest user is the one with the largest ID, and ordering by "ID DESC Limit 1" automatically selects the single record with the largest ID.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...