You are here: Re: SQL Join « MsSQL Server « IT news, forums, messages
Re: SQL Join

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация