Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Max date
Message
 
 
To
11/01/2006 20:44:10
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
01085916
Message ID:
01085923
Views:
16
This message has been marked as the solution to the initial question of the thread.
Try
Select policy, exp_mod, eff_date ;
	from mytable mt1 ;
	WHERE NOT EXISTS ( ;
		SELECT * FROM mytable mt2 ;
			WHERE mt2.policy = mt1.policy AND mt2.eff_date > mt1.eff_date) ;
	into cursor xxx

* or

Select policy, exp_mod, eff_date ;
	from mytable mt1 ;
	WHERE eff_date = ( SELECT MAX(eff_date) FROM mytable mt2 ;
			WHERE mt2.policy = mt1.policy) ;
	into cursor xxx
>I have a table with 3 fields - policy number, exp_mod, eff_date. There are many records for each policy number.
>
>I need to get the exp_mod for each policy with the latest eff_date.
>
>If I use the following code I get two or three record as opposed to the exp mod associated with the lastest date
>
>
>Select policy,exp_mod,max(eff_date) from table exp_mod_table ;
>group by policy,exp_mod into cursor xxx
>
>
>
>I assume I could order the results in descending order by eff_date and then select the first record for each policy, but there surely have to be a better way.
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform