Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange 'group by' behavior
Message
From
09/05/2002 14:26:53
 
 
To
09/05/2002 14:17:05
John Deupree
Long Term Care Authority
Tulsa, Oklahoma, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00654671
Message ID:
00654676
Views:
12
John,

I would add the ORDER BY (see below) clause to the subquery...although I would expect you to possibly get more results (duplicates) without it, rather than no results.

>I often use code like this to return the record in a group with the highest (latest) value.
>
>SELECT * FROM temp1 ;
>	INTO CURSOR temp2 ;
>	WHERE 	STR(con_id) + DTOS(plan_end_date) IN ;
>	(SELECT STR(con_id) + DTOS(MAX(plan_end_date)) ;
>	FROM temp1 ORDER BY con_id ;
        GROUP BY con_id)
>
>The code above is run on a cursor (temp1) that is a join of a parent and child table where the PK of the parent (con_id) = the FK of the child (plan_con_id). Both fields con_id and plan_con_id are in cursor temp1. Temp1 looks like this:
>
>con_id  con_lname  con_fname  plan_con_id  plan_end_date
>123     smith      john       123          01/01/2002
>123     smith      john       123          01/01/2001
>etc.
>
>When I run the above using plan_con_id (the FK) instead of con_id (replace each instance of con_id), no records are returned. When I switch to con_id, it runs correctly and returns one record with the latest date and associated consumer fields. Since the values are the same for con_id and plan_con_id, why would it make a difference using one over the other?
>
>TIA
>John
Steve Gibson
Previous
Reply
Map
View

Click here to load this message in the networking platform