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

select the last modified line for each item

Status
Not open for further replies.

yakata

Programmer
Dec 13, 2000
30
0
0
FR
Hi there,

So stupid I think, I just have a table with a list of devices and the date of their last check.

I need to list only one line per device which is the last check date.
Help me, i'm stuck, tryin to use max but I can't figure out how to deal with the distinct and group by clauses...

TIA for a reply
 
I basically have a similar issue as Yakata...except that I also want the other fields of the record to be in the result. When I try to do this, it wants to use some sort of aggregate function on each field. I figure that once it has grouped, then found the max of a particular field, it should be easy to pull in the other fields on that same record. I do this all the time usng a report writer...but MS Query has me stuck!
 
Try this:
Code:
select        a.* 
from          table a,
              (select     key, 
                         max(updatedate) 'max_date'
              from       table
              group by   key) b
where         a.key = b.key
              and a.updatedate = b.max_date

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top