Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL command: syntax needed
Message
From
22/03/2004 14:04:41
 
 
To
22/03/2004 10:37:33
Bruno Maddalozzo
Informatica Aziendale
Arsie, Italy
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00888526
Message ID:
00888610
Views:
12
>I need a query to extract the most recent price inserted for a product
>i.e.
>
>
>id_product    year   price
>1             2004   12004
>1             2003   12003
>2             2003   22003
>2             2002   22002
>
>
>so as to obtain
>
>id_product    year   price
>1             2004   12004
>2             2003   22003
>
>
>
>Which is the SQL syntax to perform the Select?

YOu need to do this in two steps:

SELECT id_product, MAX(year) AS MostRecent ;
FROM YourTable ;
GROUP BY 1 ;
INTO CURSOR Recent

SELECT id_product, Year, Price ;
FROM YourTable ;
JOIN Recent ;
ON YourTable.id_product = Recent.Id_product ;
AND YourTable.Year = Recent.MostRecent ;
INTO CURSOR Result

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform