Pulling MAX ID query pulls to many returns

I have a query that shows me the information on students we serve. The query pulls all of their classes and the status results as well as contact information. I need to query down to the LAST class taken and the students status. If I take out the following fields I get the correct return but I have to have all the information

"dbo.Class.Year, dbo.ClassResult.ClassResultStatusID, dbo.Class.SemesterID, dbo.Location.LocationName, dbo.Institution.InstName"*

SELECT MAX(dbo.ClassResult.ClassID)AS LASTCLASS, dbo.Person.PersonID, dbo.Person.LastName, dbo.Person.FirstName, dbo.Address.Address1, dbo.Address.City, dbo.Address.State, dbo.Address.Zip, dbo.Class.Year, dbo.ClassResult.ClassResultStatusID, dbo.Class.SemesterID, dbo.Location.LocationName, dbo.Institution.InstName

FROM dbo.Person
INNER JOIN dbo.Person_Address ON dbo.Person.PersonID = dbo.Person_Address.PersonID
INNER JOIN dbo.AddressON dbo.Person_Address.AddressID = dbo.Address.AddressID
INNER JOIN dbo.ClassResult ON dbo.Person.PersonID = dbo.ClassResult.PersonID
INNER JOIN dbo.Class ON dbo.ClassResult.ClassID = dbo.Class.ClassID
INNER JOIN dbo.V_ClassResultStatusID ON dbo.ClassResult.ClassResultStatusID = dbo.ClassResult.ClassResultStatusID
INNER JOIN dbo.V_SemesterID ON dbo.Class.SemesterID = dbo.Class.SemesterID
INNER JOIN dbo.Location ON dbo.Class.LocationID= dbo.Location.LocationID
INNER JOIN dbo.Institution ON dbo.Person.InstitutionID = dbo.Institution.ID

Group by dbo.Person.PersonID, dbo.Person.LastName, dbo.Person.FirstName,
dbo.Address.Address1, dbo.Address.City, dbo.Address.State,
dbo.Address.Zip, dbo.Class.SemesterID, dbo.Class.Year,
dbo.Location.LocationName, dbo.Institution.InstName

(dbo.ClassResult.ClassResultStatusID NOT IN (4, 8, 10, 12, 13)


ORDER BY dbo.Person.LastName, dbo.Person.FirstNam

more ▼

asked Dec 02, 2009 at 11:50 AM in Default

avatar image

Cathy Brashear
2 2 2 3

(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Dec 02, 2009 at 11:50 AM

Seen: 1049 times

Last Updated: Dec 02, 2009 at 02:32 PM

Copyright 2016 Redgate Software. Privacy Policy