Re: Seems like an easy query, but isn't to me. Help?

2010-08-20 Thread Jangita

On 20/08/2010 2:45 a, 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?

Thanks,
George

Can you send the table create statement so that we can see the 
structure? I'm guessing the date field is called uudate? (also specify 
the field that you want to populate with the record before) Is the 
primary key field uuid? are all the numbers in the primary key field 
sequential (1,2,3,4) with no gaps? I do have an idea but i need this 
info to see if it can work.

--
Jangita | +256 76 91 8383 | Y!  MSN: jang...@yahoo.com
Skype: jangita | GTalk: jangita.nyag...@gmail.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Seems like an easy query, but isn't to me. Help?

2010-08-20 Thread Shawn Green (MySQL)

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



Seems like an easy query, but isn't to me. Help?

2010-08-19 Thread George Larson
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?

Thanks,
George