-2

Suppose we have multiple records of the following form:

A B C date1
A B C date 2 D E F date3
D E F date 4

I want to only select the distinct records where the date is the largest. So if date2 is the largest, chose that ABC record. Similarly, if date3 is the largest, choose that DEF record.

NebulousReveal
  • 562
  • 2
  • 7
  • 19

1 Answers1

0

Easiest way is probably something like this;

SELECT A, B, C, Date
FROM table t1
WHERE Date = (SELECT MAX(Date) FROM table t2 WHERE t2.A = t1.A AND t2.B = t1.B AND t2.C = t1.C)

Cleaner would be to make a CTE (or subquery), to get the max date for each combination of other columns, then join back to that from the table

Milney
  • 6,253
  • 2
  • 19
  • 33