user1600843
user1600843

Reputation:

Select last entry from sql database

I want to select the last entry from my database.

$sql = "SELECT LAST(time) FROM pikkertonnode_415629569";
$erg = mysql_query($sql) or die ("Can't do it");

while ($data = mysql_fetch_array($erg))
{
$x = $data['time'];
...

Everytime i get the message ,,Can't do it"

Can you help me?

Upvotes: 0

Views: 1220

Answers (2)

juergen d
juergen d

Reputation: 204924

If you want the latest complete record and not just the biggest value of one column you can do

SELECT * FROM pikkertonnode_415629569
order by `time` desc
limit 1

if you have a time column actually...

Upvotes: 2

John Woo
John Woo

Reputation: 263933

use MAX

$sql = "SELECT MAX(time) AS max_time FROM `pikkertonnode_415629569`"

Upvotes: 3

Related Questions