🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #900

Find the record with the last operation

#900
From: Jorge
Date: Fri, 13 Apr 2007 19:46
42 lines
2353 bytes
Hello there,

Here's my scenario: We have three delivery trucks. On any given day, each 
truck can perform from one to four deliveries. Each delivery is numbered 
sequentially.

Here's a sample of our data in the DELIVERIES table:

TRUCK | DELIVERY | DATE | TIME
--------------------------------------------
1    1    03/31/2007    10:15            *
2    1    03/31/2007    10:25
2    2    03/31/2007    11:25            *
3    1    03/31/2007    10:30
3    2    03/31/2007    11:30
3    3    03/31/2007    12:30            *

To simplify things in this example: truck 1 did one delivery, truck 2 did 
two deliveries, and truck 3 did three deliveries.

I've put an asterisk next to the records I need to extract for any given 
day: I need one record per truck, the one with the last delivery for it. So, 
the result set should be:

TRUCK | DELIVERY | DATE | TIME
--------------------------------------------
1    1    03/31/2007    10:15            *
2    2    03/31/2007    11:25            *
3    3    03/31/2007    12:30            *

These are the records with the last delivery of each truck in any given day.

Note.- The last delivery record for each truck is determined by the 
sequential DELIVERY field. Date and time are just for reference.

TRUCK and DELIVERY are integer fields in the DELIVERIES table. Which SQL 
SELECT statement would give me the desired result set?

Thanks in advance,

-Jorge
Using IB6
Technical Details
Message-ID: <461fde4d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,c901fd9553dd3596,start
X-Google-Attributes: gid114a0e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jorge" <no@spam.com>
Newsgroups: borland.public.interbase.sql
Subject: Find the record with the last operation
Date: Fri, 13 Apr 2007 14:46:46 -0500
Lines: 43
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
NNTP-Posting-Host: 216.62.70.17
Message-ID: <461fde4d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1176493645 216.62.70.17 (13 Apr 2007 12:47:25 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail