Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving most recent datestamp row 1

Status
Not open for further replies.

Dweezel

Technical User
Feb 12, 2004
428
GB
If you remember my post from a few days ago, this is the table structure that I'm now using (thanks CYoung and TonyGroves):

stamp DATETIME not null primary key,
year int(4) not null,
month int(2) not null,
day int(2) not null,
hour int(2) not null,
minute int(2) not null,
reading float(10,6) not null



How would I go about retrieving the results that have the most recent and most distant DATETIME from the above table? These are not necessarily the first and last rows entered in the database table, as the order in which files are parsed and entered into the database may not be chronological.

Apologies if this is remedial but I'm fairly new to sql.

I also need to fetch results by descending DATETIME. I'm guessing that this will do it:

"select * from siteTable
where stamp between $datetimeA
and $datetimeB
order by stamp desc"

I won't be able to test it out until tomorrow night. Can I do the 'order by desc' thing with datestamps?
 
Dweezel said:
How would I go about retrieving the results that have the most recent and most distant DATETIME from the above table?
the most recent is given with the MAX function --
Code:
select stamp
     , year
     , month
     , day
     , hour
     , minute
     , reading
  from daTable
 where stamp = 
       ( select max(stamp)
           from daTable )
while the most distant would use MIN
Dweezel said:
Can I do the 'order by desc' thing with datestamps?
yeppir :)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top