Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Beginner
Mar 8, 2006

Selecting One Record Before and After a Value

Suppose you want to select records from a table (say orders from a Northwind database), before and after a certain value (orderid). For instance, one order before and after 10250. You'd write a query like this:

SELECT TOP 3* FROM orders
WHERE OrderId >=(SELECT MAX(OrderId) FROM orders WHERE OrderId < 10250)
ORDER BY OrderId 
Srinath MS
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap