SQLTeam.com | Weblogs | Forums

MIN(Date)


#1

Hi, I have an SQL 2008 View that shows me Lot Number, Lot Date and Item Code, An Item Code can have More than one Lot Number so I need Just the oldest lot Date of every Item Code : example :slightly_smiling:

LotNumber | LotDate | ItemCode |
10000 | 01/01/2016 | Code1 |
10001 | 02/01/2016 | Code1 |
10003 | 01/15/2016 | Code2 |
10005 | 02/18/2016 | Code2 |

I need this way :

LotNumber | LotDate | ItemCode |
10000 | 01/01/2016 | Code1 |
10003 | 01/15/2016 | Code2 |

My Code is this :

SELECT LotNr, LotDate, ItemCode
FROM dbo.ViewVK_PO_History

Thanks in advance to all.


#2

select a.* from ( select *, row_number() over(partition by ItemCode order by LotDate) rownum from dbo.ViewVK_PO_History ) a where a.rownum = 1;


#3

Thak You so much stephen_hendricks, it works perfectly as Swiss clock.

Regards...