Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reversing an order
Message
From
04/02/2014 12:10:15
 
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01593113
Message ID:
01593152
Views:
27
>>Here is a puzzle. I have a table that contains annual records for businesses. There may or may not be a record for a given business in any given year. So for BusinessA there may be records for 2000, 2003, 2004, 2008, 2010, 2012, etc. I want to SELECT the most recent 3 records. That is easy enough.
SELECT TOP 3 * FROM [HistoricalSummary] WHERE business=@business ORDER BY [year] desc
But now here's the problem. I want the order of these records to be sorted by year lowest to highest. So this is the opposite of what is needed to get the 3 latest records. Has anyone dealt with anything like this before?
>>Thanks
>
>What will you do if the year is missing, for some reason. Say, you only have data for 2013, 2012 and 2010 missing 2011. Does it matter?

It does not matter. I want the 3 MOST RECENT records. I haven't tried it yet but I think Borislav has the answer.
Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform