Home » SQL & PL/SQL » SQL & PL/SQL » Select distinct
Select distinct [message #8240] Tue, 05 August 2003 14:45 Go to next message
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 Go to previous messageGo to next message
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);
Re: Select distinct [message #8254 is a reply to message #8241] Wed, 06 August 2003 06:42 Go to previous message
Philip F. Brantley
Messages: 2
Registered: August 2003
Junior Member
Thanks Todd - your solution works great
Previous Topic: decode problem ....
Next Topic: DECODE help!
Goto Forum:
  


Current Time: Fri Apr 19 21:08:04 CDT 2024