Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL max() and corresponding fields
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00241387
Message ID:
00241448
Views:
17
Thanks for your help. It worked with the two separated queries, but without the "LAST" function you suggest. What is that function? I did not even find documentation about it and got an error ("too many arguments") when i try to use it.

Thanks again.

>>Is it possible to get the maximum value from a field and other fields corresponding to the same record?
>>
>>i.e: Given a table with OrderNumber, CustId and total_Price, How do I get the highest total_price for every CustId and the Corresponding OrderNumber in a single query?
>>
>>I´ve tried something like:
>>Select CustId, OrderNumber,max(total_price) from [Tablename] group by CustId
>>
>>It returned the maximum value of "total_price" for every CustId, but the "OrderNumber" returned is not correct, given that in the source table the total_price for that Order_Number is not the same.
>>
>>Tks
>
>You might need two queries - one to order the records and another to give you your MAX.
>
>SELECT CustId, OrderNumber, total_price FROM yourtable INTO CURSOR curs1 ORDER BY CustId, total_price
>
>SELECT CustId, LAST(OrderNumber), LAST(total_price) FROM curs1 INTO CURSOR endresult GROUP BY CustId
>
>In the second query, LAST(total_price) and MAX(total_price) should give you the same thing.
There´s a better life... Just it´s more expensive!
Cristóbal Manrique M.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform