I have the following query
SELECT ID, TestReason
FROM Test as t
INNER JOIN TestResult as tr ON t.ID = tr.TestID
A test can have multiple test results.
The TestResults are A, B, C or D, F.
I need to say for each test, give me the max test result, but the ID’s on the test results have nothing to do with the grade, so I have to use the string.
Here are the tables:
Test
ID TestReason
int int
Test Reason
ID Grade
int varchar(2)
So basically the highest grade trumps all, so if the test (TestID = 1) contains a test result of A,C,C,D,D I need the 1 record returning like so:
1 A
How would I do this?
Maybe I am missing something but did you try this – since you are using letter grade, then you will use
MIN():See SQL Fiddle with Demo
Or you can use
row_number():See SQL Fiddle with Demo