How do I select a distinct element for a particular table based on a condition
What I am trying to do is this:

I have a table called results and t looks like this: <br>

|id| | matric_number| |session  ||Course| |grade| <br>
|1 | | 2008/22142BC | |2009/2010||MAT111| |F|  <br>
|2 | | 2008/22143BC | |2009/2010||MAT111| |F|  <br>
|3 | | 2008/22142BC | |2010/2011||MAT111| |C|  <br>
|4 | | 2008/22143BC | |2010/2011||MAT111| |F|  <br>

I have another table called sum_result, and it looks like this:<br>


|id| | matric_number| |MAT111 ||MAT112| |Defficiency||session| <br>
|1 | | 2008/22142BC | |C      ||D     | |           ||2010/2011| <br>
|1 | | 2008/22142BC | |F      ||D     | |MAT111(F)  ||2010/2011| <br>

I have no problem selecting matric_number having grade F in any of the courses in 2009/2010 session. 
but the problem is in the subsequent session .for example 2008/22142BC has now passed MAT111 with a grade C in 2010/2011 session. so it should be deducted from his deficiency, while that of  2008/22143BC should not appear two times, as it is still the same course

I will appreciate any help
How do I select a distinct element for a particular table based on a condition
===

What I am trying to do is this:

I have a table called results and t looks like this: <br>

|id| | matric_number| |session  ||Course| |grade| <br>
|1 | | 2008/22142BC | |2009/2010||MAT111| |F|  <br>
|2 | | 2008/22143BC | |2009/2010||MAT111| |F|  <br>
|3 | | 2008/22142BC | |2010/2011||MAT111| |C|  <br>
|4 | | 2008/22143BC | |2010/2011||MAT111| |F|  <br>

I have another table called sum_result, and it looks like this:<br>


|id| | matric_number| |MAT111 ||MAT112| |Defficiency||session| <br>
|1 | | 2008/22142BC | |C      ||D     | |           ||2010/2011| <br>
|1 | | 2008/22142BC | |F      ||D     | |MAT111(F)  ||2010/2011| <br>

I have no problem selecting matric_number having grade F in any of the courses in 2009/2010 session. 
but the problem is in the subsequent session .for example 2008/22142BC has now passed MAT111 with a grade C in 2010/2011 session. so it should be deducted from his deficiency, while that of  2008/22143BC should not appear two times, as it is still the same course

I will appreciate any help