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 > selecting records using a snapshot time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-06, 22:14
mabz mabz is offline
Registered User
 
Join Date: Apr 2004
Location: Wellington, NZ
Posts: 5
selecting records using a snapshot time

Hi,
Have many tables in a data warehouse that just have a snapshot time to differentiate between each set of records for a particular item. I am trying to work out the best way to select only the latest record for each item (the latest snapshot).

Here is a simple example table

TYPE,SNAPSHOT_TIME,DESCRIPTION
B,14/04/2003 23:01:42,Room
C,14/04/2003 23:01:42,Club
B,17/11/2003 23:57:46,Meeting Room
A,17/11/2003 23:57:46,Temporary
N,17/11/2003 23:57:46,National Office

Select would retrieve four records with record type of B having the description of Meeting Room.

Many Thanks
Reply With Quote
  #2 (permalink)  
Old 01-26-06, 02:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
select TYPE,SNAPSHOT_TIME,DESCRIPTION
from example as foo
where SNAPSHOT_TIME =
( select max(SNAPSHOT_TIME) from example where TYPE = foo.TYPE )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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