query to return the newest

stuartam

Registered User.
Local time
Today, 20:00
Joined
Jul 16, 2004
Messages
93
i have a table with the following fields:

IDNUM - PACKREF - STATEHISTORY - USERHISTORY- DATEHISTORY

i have a query that returns all the data with a matching 'PACKREF'

but i want it to only display the one with the newest date ( date in the 'DATEHISTORY' field )

how can i do this?

best regards
 
In the query design window, select the Sigma sign on the toolbar at the top of the screen - it looks a bit like a capital 'E'. This will add another criteria to the query grid called 'Total' (it should be underneath 'Field' and 'Table'). You can then select 'Last' from the drop-down menu next to 'Total' and it will only disply the last record of the table, which should be the record with the newest date.

I hope I've explained this ok.

Dave
 
thanks for the reply, ive tryed that but it didn't work

it just displays all the data no just the one with the newest date.

maybe ive done something wrong?

regards
 

Attachments

  • Untitled-1.gif
    Untitled-1.gif
    8.9 KB · Views: 168
Hth

SELECT
IDNUM
, PACKREF
, STATEHISTORY
, USERHISTORY
, DATEHISTORY

FROM
tblRecords

WHERE
(((tblRecords.DATEHISTORY) In (select max(DATEHISTORY) from tblRecords))); ;)
 
thanks guys, couldent get that too work either ( was probabilly putting it in the wrong place ) but i did get this too work:

Code:
(select max(DATEHISTORY) from TBLPackHistory)

thanks for all the help
 
You need to select 'Last' in all of the fields and it will only display the last record.
 

Users who are viewing this thread

Back
Top Bottom