On 8/19/2010 8:45 PM, George Larson wrote:
I hope I've come to right place, and I'm asking in the right way -- please
accept my apologies if not.
We have some dates missing and I need to populate those fields with dates
from the record just before them. I've gotten this far:
SELECT UUid, MIN(DDenteredDate) minDate FROM UUtable JOIN DDdetail on DDid =
UUid
WHERE
UUdate IS NULL
GROUP BY UUid;
I can make this a sub-query and get the UUid of the record that I want to
copy UUdate from:
SELECT sub.UUid-1 as previous, sub.* FROM (
SELECT UUid, MIN(DDenteredDate) minDate FROM UUtable JOIN DDdetail on DDid =
UUid
WHERE
UUdate IS NULL
GROUP BY UUid;
) as sub;
In this case, the field 'previous' is the UUid that I want to copy the
UUdate from and sub.UUid is where I want to copy to.
Does that even make sense?
As you discovered, the SQL language is not an ordinal, procedural
language. It is a SET-oriented language. The sequence of rows in any one
set of results completely depends on either how those rows were isolated
from the table(s) on which they reside (random) or by an ORDER BY or
similar secondary processing step. Without an ORDER BY, it is perfectly
legal for the same query to return the same set of rows in completely
different sequences for queries that are executed one immediately after
the other.
If you want to say "the record just before" when referring to SQL data
and have it mean anything, you must be specific about how you are
sequencing your rows. Only then do the concepts of "before" and "after"
have any meaning.
--
Shawn Green
MySQL Principal Technical Support Engineer
Oracle USA, Inc.
Office: Blountville, TN
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org