Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with MAX() in SELECT
Message
 
 
To
23/01/2002 09:51:00
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Contracts, agreements and general business
Miscellaneous
Thread ID:
00608962
Message ID:
00609503
Views:
25
Hi Agnes,

VFP returns values for the fields not included in the GROUP BY clause from the last physical record in the group not from the record with MAX()/MIN() value. You can get desired result with two selects
SELECT;
 Work_Table.Code, MAX(Ref_Table.Code) as max_code;
 FROM Work_Table ;
 INNER JOIN Ref_Table ;
 ON Work_Table.Code = STRTRAN(Ref_Table.Code, " ", "") ;
 GROUP BY 1 ;
 INTO CURSOR temp1

SELECT;
 temp1.Code, ref_Table.Key, temp1.max_Code ;
 FROM temp1 ;
 JOIN Ref_Table ;
	 ON temp1.max_Code = Ref_Table.Code ;
 INTO CURSOR crsresult	 
BTW, I couldn't get the first select work with ALLTRIM() because VFP just ignored it. That's why I replaced it with STRTRAN().

< snip >
>
>IF try to use a SELECT SQL with a syntax like the following:
>
>
>SELECT;
> Work_Table.Code,Key_Table.Key,MAX(Ref_Table.Code);
> FROM Work_Table;
> INNER JOIN Ref_Table;
> ON Work_Table.Code=ALLTRIM(Ref_Table.Code);
> GROUP BY 1
>
>
>The result is, that I get the correct Code from Ref_Table, and a wrong Key.
>
>What's wrong with my statement?
>
>Thanks for Help
>
>Agnes
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform