Yes, others have been giving you a hard time, but now you know to show what you have seriously attempted to do for problem solving. Although none have worked for you, I will try to help by explaining as I go.
First, start with the courses table alone as that has the ID of the teacher we can work with after. This is a simple group by clause.
select ;
c.id, ;
max( c.length ) as CourseMaxLen ;
from ;
courses c ;
group by ;
c.id ;
into ;
cursor C_MaxCoursePerTeacher
Then, you could browse this result to see. Now, you have a very simple query per teacher. You can then use this as the basis to join to the teacher table to get the teacher name. Then join again back to the original courses table by the teacher and length of the course. However, if you have a teacher that has multiple courses of the same length, each of the same length will be returned.
select
CMax.ID, ;
T.Name as TeacherName, ;
c2.Name as CourseName,;
c2.Length ;
from ;
( select ;
c.id, ;
max( c.length ) as CourseMaxLen ;
from ;
courses c ;
group by ;
c.id ) CMax ;
JOIN Teachers t ;
on CMax.ID = t.id ;
JOIN Courses c2 ;
on CMax.ID = c2.ID ;
AND CMax.CourseMaxLen = c2.Length
Notice the join to the courses (c2) is by both the teacher's ID AND The maximum length determined from the inner query. Try to take the pieces of your puzzle problems one at a time, then blend together as needed.
Additional option for you in VFP... AS YOU are LEARNING, build the pieces and query them into temporary cursors to be used for the next step. The working example could have also been done as using the original query
INTO CURSOR
C_MaxCoursePerTeacher
Then using that as the join such as ...
select
CMax.ID, ;
T.Name as TeacherName, ;
c2.Name as CourseName,;
c2.Length ;
from ;
C_MaxCoursePerTeacher CMax ;
JOIN Teachers t ;
on CMax.ID = t.id ;
JOIN Courses c2 ;
on CMax.ID = c2.ID ;
AND CMax.CourseMaxLen = c2.Length
This way, you can get one working query done at a time, know what its purpose if for, then move to the next piece(s) of the puzzle.