RE: Selecting range of rows

RE: Selecting range of rows

 

  

Selecting A Range of Records (Rows) In SQL Server 2000

--Select record 1 only from the Orders table in the Northwind Database
SELECT TOP 1 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 0 orderID
FROM orders
ORDER BY orderID)
ORDER BY orderID

--Select record 2 only from the Orders table in the Northwind Database
SELECT TOP 1 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 1 orderID
FROM orders
ORDER BY orderID)
ORDER BY orderID

--Select records 11-20 from the Orders table in the Northwind Database
SELECT TOP 10 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 10 orderID
FROM orders
ORDER BY orderID)
ORDER BY orderID

--Select last record only from the Orders table in the Northwind Database
SELECT TOP 1 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 1 orderID
FROM orders
ORDER BY orderID)
ORDER BY orderID DESC

--Select last 3 record only from the Orders table in the Northwind Database
SELECT TOP 3 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 3 orderID
FROM orders
ORDER BY orderID)
ORDER BY orderID DESC



________________________________

From: Juan Vera [mailto:mssqldba-ezmlmshield-x23971217.[Email address protected]
Sent: Tue 6/28/2005 5:52 PM
To: LazyDBA Discussion
Subject: RE: Selecting range of rows



> I need to select the first 65,000 rows and place it in excel, then I
> need to select the rest of the records 65,000 to 93,000. How do I
write
> the query? I know I can write to grab "TOP 65,000, but how do I grab
> the rest?

Select *
From myTable
Where primaryKey not in (
Select top 65000 primaryKey
From myTable)

<g>



---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
Website : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html




MS Sql Server LazyDBA home page