I have two databases, one containing students and the other one containing their marks. I want to be able to extract from them via single query list of students' names from first table and their maximal mark+name of subject they got it for. I know this example does not work:
SELECT LastName, FirstName, ID,
(
SELECT TOP 1 MIN(Mark), Subject
FROM Marks as o
GROUP BY Mark
) as (minMark, minSubject),
(
SELECT TOP 1 MAX(Mark), Subject
FROM Marks as O
WHERE o.StudentID = C.ID
) as (maxMark, maxSubject)
FROM Students as C
But it shows perfectly what I need. How can one achieve an effect like this?
+It is not duplicate, mysql solution will do me nothing good.