× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I apologize if I'm missing something here but I would have thought you could
just use a grouping to accomplish this.  You should be able to group by
date, time having Max(date),max(time) right?

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Dan
Sent: Thursday, June 15, 2006 1:59 PM
To: Midrange Systems Technical Discussion
Subject: Cool but ugly SQL

I'm told this can be done.  But I'm having a bugger of a time figuring this
out.  And it's starting to be crunch time.  My file layout:

 SHH_LIB    Char         10
 SHH_FILE   Char         10
 SHH_MEMBER Char         10
 SHH_LCDATE Date         10
 SHH_LCTIME Time          8
 SHH_HASH   Char         20

The file key is the first five fields, which makes the key unique.
Duplicate values for the first three key fields are allowed and expected.
My task is to select the Lib/File/Member with the highest timestamp (LCDATE
& LCTIME), omitting any duplicate Lib/File/Member with earlier timestamps.
I'm also selecting certain library and file values.  Here is my current SQL:

  Select * from SRCMBRHASH where
        shh_Lib = 'PRODSRCE' and shh_File LIKE 'Q%'
    and shh_LCDate = (Select Max(shh_LCDate) from SRCMBRHASH
      where shh_Lib = 'PRODSRCE' and shh_File LIKE 'Q%' )
   Order by shh_Lib, shh_File, shh_Member, shh_LCDate desc,
             shh_LCTime desc

This "works", as in no syntax errors, but the result set is way too small.
I would expect every unique Lib/File/Member to appear (approximately 100),
but I'm only getting three rows.

Problem 1: How do I select the MAX of two fields, LCDate and LCTime?  (I
know, should be a real timestamp field, but that's a fix for the next
version.)
Problem 2: I think I need to compare shh_Lib to shh_Lib, shh_File to
shh_File, and shh_Member to shh_Member from the two selects in the
subselect.  But how?

TIA,
Dan

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.