If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > First & last record retrieve

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-03, 13:25
Plarde Plarde is offline
Registered User
 
Join Date: Jan 2003
Posts: 54
First & last record retrieve

Is there a simple SQL statement to get the
last and first record of a table under
Access and SQL Server ?

Thanks,
Pierre.
__________________
Pierre (Pl-Arts)
Reply With Quote
  #2 (permalink)  
Old 02-17-03, 14:16
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: First & last record retrieve

Tables have no concept of "first" and "last". You need to create a column by which you can order the data. Then you can do something like:

SELECT * FROM t WHERE col IN (SELECT MIN(col) FROM t
UNION SELECT MAX(col) FROM t);
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On