This is doing my nut in...
OK I have a table called UserTest which stores users' test results. The fields are UserTestID(PK), TestID(FK), Score, Username(FK).
Now basically I want a control (dropdownlist, gridview etc (anything that will work really)) which populates with each users' best score for a test (determined by another control [fine with this bit])
At the moment (since a user can have multiple results for a single test) I can only get it to list each distinct score, which leads to usernames being listed more than once since some have attempted a test more than once and got different scores. Query at the moment is below:
Research leads me to believe this can be achieved by combining distinct and MAX but I've tried it and I'm getting nowhere.
Anyone help me?
OK I have a table called UserTest which stores users' test results. The fields are UserTestID(PK), TestID(FK), Score, Username(FK).
Now basically I want a control (dropdownlist, gridview etc (anything that will work really)) which populates with each users' best score for a test (determined by another control [fine with this bit])
At the moment (since a user can have multiple results for a single test) I can only get it to list each distinct score, which leads to usernames being listed more than once since some have attempted a test more than once and got different scores. Query at the moment is below:
Code:
SELECT DISTINCT [TestID], [Score], [UserName] FROM [UserTest] WHERE ([TestID] = @TestID)
Research leads me to believe this can be achieved by combining distinct and MAX but I've tried it and I'm getting nowhere.
Anyone help me?