this Returns the last row from a select where multiple rows in a database table. for example, lets say i have a table called users, and i want to get the last user who registered with the userid as the row. i could use this mysql query:
Code/Command:
$qry = "SELECT * FROM users ORDER BY userid DESC LIMIT 1";
?>
related questions:
How to find last row and last column of table
Retrieving last row inserted
How to select the Last row from a table..using Mysql - MySQL
How to retrieve the last row in MYSQL database using SELECT
Comments and replies About Mysql How To Select Display Last Row Item Retrieve Query SQL From Database
hmm:
eee..
but.. how to display 10 last comment ?
fernand:
thank you i needed help in using queries to get the last row in a database
wallpaperama:
if you want to select the last 10 rows for example you would use this query:
$sql = "SELECT this FROM users ORDER BY userid DESC LIMIT 0,10";
however, if you want to look for the first 10 rows of userid then you would just change the ORDER to ASC (ascending) like this:
$sql = "SELECT this FROM users ORDER BY userid ASC LIMIT 0,10";
if you have more questions about this tutorial let me know. i am very knowledgable with mysql
lucas:
im intereasted in getting and retrieving last row inserted also How to find last row and last column of table
Lillian:
i am trying to insert the file name of an image stored on the server into a field in the last row of mysql database. how do i do this? lillian.
Alvin:
thank you very much! it's work :)
kate414:
this works pretty fine when you have an auto-incremented field but how can you get the last row with a varchar field?
Colin:
i had the same problem. i've worked out what i think is a nice solution. check it out at <a href=" colincoderre /mysqlselectlastnrows.php"
title="mysql - select last n rows, by colin coderre"
target="_blank"><b>mysql - select last n rows</b></a>
asd:
hi bye hi bye hi bye hi bye
Glen:
hmm, thats quite easy though it helps for us.
try this..
for mssql
select top 1 * from tblname order by column DESC
or visit this site makeitworth.ph