Selecting Max of a field for a Query

chris_jolly

Registered User.
Local time
Today, 13:18
Joined
Jul 27, 2007
Messages
24
Hello,

I have a link table where I am forming a union query from and would like to take a specific set of data. The table is a timestamp table and I would like to grab the most recent entry. So in theory, I want the max value for the timestamp. I writing this in sql to facilitate the union query.

Table: Time Submitted - ####(corresponding plant)
Fields: Plant, Version, Timestamp

So I want to take the plant, version, and timestamp that corresponds to the most recent Timestamp

This is my current SQL, i dont know if the where statement is correct

Select *
From [Time Submitted - ###]
Where ????
 
I think that the best way to do this is to sort ascending on the timestamp field and select the Top 1

Brian
 
How would I go about picking the specific record then? I wouldnt have to sort it, the last record is the most recent.

If you could give me an idea how to grab a specific record or row, I could accomplish this task easily.
 
The last record entered may be the one you want but that is not nescessarily physically the last one in a relational database.

You run a query selecting all the fields you want, sort ascending on the time stamp and select Top 1, thus selecting the data with the highest(max) time stamp. Using Max ,an aggregate function, introduces all sorts of complications.

Brian
 
Hi
Just noticed that this is in the SQL Server Forum, so maybe I've been talking rubbish if things are different from ACCESS, if so I apologise.

Brian
 

Users who are viewing this thread

Back
Top Bottom