I have a post table and postcontent table.
Each time post is edited,an entry is added to postcontent table .
On each such time a filed called version will be incremented by 1 In the postcontent table.
How can I fetch PostId, from post able and [Description] from to postcontent table Where version for each post is maximum Ie group by post id ie i am expecting one raw for each post such that it is the 'maximum of version' for the post
select P.PostID,
PC.[Description]
from Post as P
inner join
(
select PostID,
[Description],
row_number() over(partition by PostID order by [Version] desc) as rn
from PostContent
) as PC
on P.PostID = PC.PostID
where PC.rn = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With