i have an oracle database table,
freightcostdeviation, that contains columns and rows that look like this:
Quote:
MBRID | FREIGHTERMEMBERID | FREIGHTERNAME | DATECREATED
Grocer A | DanTestTransporter | Dan Test Transporter | 2009-02-01
Grocer A | Tollfreighter | <null> | 2009-01-01
Grocer A | TransporterPlus | Transporter Plus AS | 2009-05-16
Grocer A | FreightNorway | Freight Norway Shipping Supply Chain AS | 2008-12-04
Grocer A | Tollfreighter | Tollfreighter | 2009-03-12
Grocer A | FreightNorway | Freight Norway Supply Chain AS | 2009-09-27
Grocer B | NorwegianShipping | Norwegian Shipping AS | 2009-08-30
|
there are other columns in the table, but these are the relevant ones. i want a resultset with a distinct
freightermemberid column (no duplicates) with only the newest
freightername. i dont need the
datecreated in the resultset. i only want results for
Grocer A.
heres how i solved the problem:
Code:
SELECT t1.freightermemberid, t1.freightername
FROM freightcostdeviation t1
WHERE t1.datecreated IN (
SELECT max(t2.datecreated)
FROM freightcostdeviation t2
WHERE t2.mbrid='Grocer A' AND t2.freightermemberid = t1.freightermemberid
);
the result looks like this:
Quote:
FREIGHTERMEMBERID | FREIGHTERNAME
DanTestTransporter | Dan Test Transporter
TransporterPlus | Transporter Plus AS
Tollfreighter | Tollfreighter
FreightNorway | Freight Norway Supply Chain AS
|