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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get maximum value only 5

Status
Not open for further replies.

PAULCALLAGHAN

Technical User
Sep 4, 2001
165
CA
I'm using Access 2000 and having trouble developing a simple query.

I would like the user to select based on a part number but I only want the results to show the highest (most recent) date value of all the records returned for that particular part number.

Can someone please tell me how I would do this with SQL, or how my query grid would look like to achieve this?

 
Something like this:

select part_id,part_name,part_date
from yourtable t1
WHERE t1.part_date In ( Select top 1 t2.part_date
from yourtable t2 Where t1.part_id=t2.part_id
Order by t2.part_date DESC )


-L
 
Thank you for the prompt reply Lothario.

But when I type it in I get an error message.

Syntax error. in query expression 't1.part_date In (Select top 1 t2.part_date ...DESC)'.

When I click OK to this message it then highlights the entire Select statement.

What am I doing wrong?
 
And what about this ?
SELECT part_id,part_name,part_date
FROM yourTable T1
WHERE T1.part_date = (SELECT Max(T2.part_date)
FROM yourTable T2 WHERE T2.part_id=T1.part_id)
;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Here's another possibility for you. It's very similar to Lothario's suggestion:

select t1.part_id, t1.part_name, t1.part_date
from yourtable t1
WHERE t1.part_date = ( Select max(t2.part_date)
from yourtable t2 Where t2.part_id = t1.part_id )

Hope this helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top