[PHP-DB] Selecting last record only

2004-01-21 Thread -{ Rene Brehmer }-
Hi gang

this is probably ridicously simple, but I'm new at this SQL stuff, so am a
bit stumped.

It's pretty simple: how do I get only the last record from a single table?

Trying to convert my file-based website into DB-based, but can't quite
figure out how to do this simple task.

Table name is history, and only have 3 fields:
histID, date, entry

I need it to pick the last record without knowing the date of it. Got
picking specific records down good, but be damned if I can figure this one
out...

TIA

Rene
Rene Brehmer
aka Metalbunny

http://metalbunny.net/
References, tools, and other useful stuff...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Selecting last record only

2004-01-21 Thread Micah Stevens
Reverse the order and limit the result to 1. 

For example, change:
SELECT date, item from some_table

To:

Select date, item from some_table ORDER BY date DESC LIMIT 1

to get the latest dated item. 

-Micah

On Wed January 21 2004 11:49 am, -{ Rene Brehmer }- wrote:
 Hi gang

 this is probably ridicously simple, but I'm new at this SQL stuff, so am a
 bit stumped.

 It's pretty simple: how do I get only the last record from a single table?

 Trying to convert my file-based website into DB-based, but can't quite
 figure out how to do this simple task.

 Table name is history, and only have 3 fields:
 histID, date, entry

 I need it to pick the last record without knowing the date of it. Got
 picking specific records down good, but be damned if I can figure this one
 out...

 TIA

 Rene
 Rene Brehmer
 aka Metalbunny

 http://metalbunny.net/
 References, tools, and other useful stuff...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Selecting last record only

2004-01-21 Thread -{ Rene Brehmer }-
thx a bunch :) ... figured it would be something simple ... :p

Rene

Fate would have it, that on Wed, 21 Jan 2004 11:55:23 -0800, Micah Stevens
wrote:

Reverse the order and limit the result to 1. 

For example, change:
SELECT date, item from some_table

To:

Select date, item from some_table ORDER BY date DESC LIMIT 1

to get the latest dated item. 

-Micah

Rene Brehmer
aka Metalbunny

http://metalbunny.net/
References, tools, and other useful stuff...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php