Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group by clause in vfp8
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00774269
Message ID:
00774748
Views:
31
Patrick,
Instead of using the physical location, use the value you're interested in.
select attd_id, max(sem_time) sem_time from sem group by attd_id into cursor sem_time

select sm.attd_id, st.sem_time, sm.sem_loc, sm.sem_cost ;
   from sem sm, sem_time st ;
   where sm.attd_id = st.attd_id and sm.sem_time = st.sem_time ;
   order by attd_id
Depending on whether you want the latest or earliest class, you use MAX() or MIN() in the first query.

HTH.

>I have always used the group by to get the last physical record in the table and have found that the results have been always been what I expected. I would like to convert my code to play by the VFP8 rules. Does anyone have a good way to get to the same result using proper SQL?
>
>I have a table with attendees and information about the seminar they attended.
>
>Select * from sem order by sem_time desc into cursor sem
>
>Select attd_id, sem_time, sem_loc, sem_cost ;
>from sem ;
>group by attd_id ;
>into cursor sem2
>
>This gives me the information about the last or first seminar of each attendee depending on the order I specify in the first statement.
>
>I would like to continue using only SQL statements, is there a simple solution given the new constraints on Group by?
>
>
>
>
>>
>>Pedro,
>>In previous version of VFP, if you did not specify a field in the Group By clause, VFP would use the value associated with the record that occured last physically in the table. If you sorted the same table or packed it, you could end up with the same query returning two different results. This was considered to be a bug and was corrected in VFP 8.
>>
>>If you don't care what values wind up in the extra columns, then don't include them in the query. This will decrease the number of fields you need to add in the Group By clause.
>>
>>Regards.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform