I need help with an SQL Query to get Data from an SQL Server Databas. I need an SQL query which would get the 2nd last record from a table.
To explain this further if the table I need to pull data from looks like the following:
Table Name: Orders
OrderID OrderDate Item
1 02/09/2010 Apple
2 04/09/2010 Mango
3 05/09/2010 Orange
4 06/09/2010 Bannana
I would like my MyQuery to get me the 2nd last record that is with OrderID 3. The following query gets me the last (most recently saved record that is the one with OrderID 4 from the Orders Table.
MyQuery = "SELECT TOP 1 * FROM Orders"
I would like a modification of the above query that would get me the record with OrderID3.
I WOULD ALSO LIKE a modification of this query that would get me the 3rd last Record (that is the record with RecordID 2 from the this table.
Many thanks for your help. Please note I am using Visual Studio 2008