I am familiar with basic queries in SQL, but I need to apply a filter and I’m not entirely sure how to go about it.
I current have this query:
var query = (from solvedPuzzle in db.SolvedPuzzles
where solvedPuzzle.UserID == user.ID
select solvedPuzzle);
And I want to modify the query or filter the results like this pseudocode:
for each pair (a,b) of results
if a.PuzzleID == b.PuzzleID
filter out a.NumberOfMoves > b.NumberOfMoves ? a : b
In case that isn’t straightforward enough, I’ll give example results of the filter
Table SolvedPuzzles:
ID UserID PuzzleID NumberOfMoves
1 2 1 5
2 2 1 6 //Will be filtered out
3 2 2 7
4 3 1 8 //Will be filtered out
5 3 1 6
6 4 2 5
7 5 2 4
That is, those two will be filtered out of the results because they are by the same user and the same puzzle, but with a greater number of moves.
1 Answer