T-SQL Order records based upon a group

Quite often you want to find the latest record order of records based upon a group of data.  Using group you would have to then join back onto the table to filter the data further. Using partition and ronumber you can do this without having to group.


select

FieldA,

FieldB,

FieldC,

row_number() over( partition by FieldA,Field B order by FieldC ) As RowNumber

From Table

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s