I have a table that looks like this:
Id PageId Key Content LastUpdated
---------------------------------------------
1 12 key1 content1 02-21-2010
2 12 key1 content2 02-25-2010
3 12 key2 content1 02-21-2010
4 12 key2 content2 02-25-2010
5 12 key3 content1 02-21-2010
What I need to be able to do is query out a distinct list by PageId ordered by LastUpdated so my result would look like this:
2 12 key1 content2
4 12 key2 content2
5 12 key3 content1
I am using Linq-2-Sql but if I needed to I could use an SP. Any help on how to accomplish this would be great, thanks!
Here’s one idea using just tsql that you could put in an SP. (Assumes that LastUpdated is a datetime field and not a string in the format you’ve listed and assumes at least SQL 2005 to use the CTE. Either of these assumptions can be overcome if they’re incorrect.):