Unstoppable Domains

How to query the last row in a table?

Spaceship Spaceship
Watch

FreeBaGeL

Established Member
Impact
2
What would the query be to pull out the last row in a table that is constantly changing?

As a note the table has an id field for each row that increments by 1 everytime a new row is added.

It's an access database if that matters (coding in ASP.net), but the query itself should be pretty similar if not the same as MYSQL.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
ok. well in mysql, you get how many rows there are in the table (mysql_num_rows), subtract 1 from it, and then use the query "select * from your_table limit (the number of rows - 1), 1" i believe.
 
0
•••
You could select the rows and order them by the id descending, then limit it to one. It would just return the first one, which is the one with highest id, which is the newest/last row.
 
0
•••
Try this:

SELECT MAX(id) AS NewestEntry FROM table;
 
0
•••
Code:
SELECT * FROM `table_here` ORDER BY `id` DESC LIMIT 1
that will give you the last row in the database, as long as you have auto_increment turned on.
 
1
•••
siverspike said:
Code:
SELECT * FROM `table_here` ORDER BY `id` DESC LIMIT 1
that will give you the last row in the database, as long as you have auto_increment turned on.

That is the perfect example. Make sure you have an id field and that it is a primary key and auto-increment (meaning everytime a new row is entered it is given an auto id).
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer

We're social

Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back