Select distinct [message #8240] |
Tue, 05 August 2003 14:45 |
Philip F. Brantley
Messages: 2 Registered: August 2003
|
Junior Member |
|
|
I have a table joapdata(joapdataid, enginedataid, sampledate,....)
I want to select a distinct value for the enginedataid and that value value based on the max sampledate.
The sample data looks like this
enginedataid sampledate joapdataid
------------ ---------- ----------
1 05-Aug-2003 1
1 06-Aug-2003 2
2 07-Aug-2003 3
2 08-Aug-2003 4
I need only one record per enginedataid but the record needs to be the max date for the group
|
|
|
Re: Select distinct [message #8241 is a reply to message #8240] |
Tue, 05 August 2003 15:09 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
There are several ways to approach this, but the most common is:
select *
from joapdata
where (enginedateid, sampledate) in
(select enginedateid, max(sampledate)
from joapdata
group by enginedateid);
|
|
|
|