Re: Go to specified row

From: Itzik Ben-Gan (itzik_at_REMOVETHIS.SolidQualityLearning.com)
Date: 08/27/04


Date: Fri, 27 Aug 2004 23:45:36 +0300

Something to keep in mind when talking about row numbers (besides the fact
that some people will probably bash you for the notion of a row number in a
relational environment :-), is that you need to provide a deterministic sort
criteria (unique).
e.g., give me the 15th most recent order. Most recent is defined by
orderdate, which may have duplicates, so here you also need to specify a
tie-breaker, e.g., orderid.
So...

USE Northwind

SELECT TOP 1 *
FROM (SELECT TOP 15 *
      FROM Orders
      ORDER BY orderdate DESC, orderid ASC) AS D
ORDER BY orderdate, orderid

-- 
BG, SQL Server MVP
www.SolidQualityLearning.com
"Eduardo Greco" <eduardo@persocom.com.br> wrote in message
news:eoG$zTHjEHA.1348@tk2msftngp13.phx.gbl...
> Hi there...
> I want to show a specific row in my table, say, the 15th row. But I want
to
> show only this row, not the previous rows.
> How to do it?
> Using SQL Server 2000.
> Thank you.
>         Eduardo
>
>


Relevant Pages

  • Re: group by help
    ... Columnist, SQL Server Professional ... "Alejandro Mesa" wrote in message ... > OrderID ... > SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • Re: Clustered vs Non-Clustered
    ... > either leave OrderId as clustered ... > OrderNumber ... > couldn't that be set as the primary key ?. ... >> OrderDate smalldatetime NOT NULL, ...
    (microsoft.public.sqlserver.programming)
  • Re: XML data to SQL Server with multiple orders and multiple order det
    ... SQLXML Bulk Load component from SQLXML 3.0. ... inserting the data using a ... OrderDate DATETIME NOT NULL ... --INSERT INTO #OrderDetails (@OrderID, ProductID, UnitPrice) ...
    (microsoft.public.sqlserver.xml)
  • Re: Problem in Select Query
    ... Wayne Snyder, MCDBA, SQL Server MVP ... > OrderId OrderItems ... > Actually I have written a query that will convert OrderItems to select ... > Using this query i got the sql statemens like this ...
    (microsoft.public.sqlserver.programming)
  • RE: ISNULL function does not work as expected on calculated field
    ... SQL Server Might Return Incorrect Results When You Use an Outer ... SELECT OrderID, (select HasStatus from constantvalue) AS HasStatus ... > handling of the ISNULL function. ...
    (microsoft.public.sqlserver.programming)