|
Posted by David Portas on 09/30/76 11:50
germanshorthairpointer@gmail.com wrote:
> Hello,
>
> I'm trying to do a join based on the following tables:
>
> Person(person_id,person_name)
> Grade(grade_id,grade_person_id,grade_score)
>
> The data looks like this:
>
> Person:
> 1,John
> 2,Dave
>
> Grade:
> 1,1,80
> 2,1,90
> 3,2,60
> 4,2,70
>
> I'd like a query that returns the each persons name along with their
> highest grade.
>
> What would the query be?
>
> Thanks!
SELECT g.grade_person_id, p.person_name, MAX(g.grade_score) AS
grade_score
FROM person AS p
JOIN grade AS g
ON p.person_id = g.grade_person_id
GROUP BY p.person_name, g.grade_person_id ;
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Navigation:
[Reply to this message]
|