Posts Tagged ‘PARTITION’

h1

Select records with Latest Date

March 8, 2011

Using ROW_NUMBER we can select records with latest date.

ROW_NUMBER  Syntax

ROW_NUMBER ( ) OVER ( [ <partition_by_clause> ] <order_by_clause> )

Example

select * from
(select <column1>,<column2>,<column3>,
ROW_NUMBER() OVER (PARTITION BY <column1> ORDER BY <dateColumn> DESC) AS ‘RowNumber’
from tablename
where condition
) A where RowNumber = 1

 

Advertisements