I recently started thread 701-894603 in which I posed the following question:
I have a table named TblPresident containing the following three fields:
LngCompetitorNo
TxtUnit
Total
"Total" is the sum of the scores from two competitions.
For each TxtUnit there are four Totals, one for each LngCompetitorNo. I need to create a query which selects the lowest two scores only for each unit.
Amorous (Programmer) replied on 5 Aug 04 12:01
Try this:
SELECT t1.*
FROM TblPresident t1
WHERE t1.Total In (select top 2 t2.Total from TblPresident t2 where t2.TxtUnit = t1.TxtUnit ORDER BY t2.Total Asc);
This code worked well but, having now entered a load of scores, I find that there are times when the query returns three results for each TxtUnit because two competitors have the same total score. I have modified the table to include the scores for each competition as well as the total so the fields in the table are now:
LngCompetitorNo
TxtUnit
Total
Roupell
Whitehead
What I need is for the query to select the lowest two scores for each unit as before but to eliminate duplicate Total scores by sorting against first, the highest Whitehead score, and next, the highest Roupell score.
Can anyone please help me to sort this one out.
Thanks a lot
John
I have a table named TblPresident containing the following three fields:
LngCompetitorNo
TxtUnit
Total
"Total" is the sum of the scores from two competitions.
For each TxtUnit there are four Totals, one for each LngCompetitorNo. I need to create a query which selects the lowest two scores only for each unit.
Amorous (Programmer) replied on 5 Aug 04 12:01
Try this:
SELECT t1.*
FROM TblPresident t1
WHERE t1.Total In (select top 2 t2.Total from TblPresident t2 where t2.TxtUnit = t1.TxtUnit ORDER BY t2.Total Asc);
This code worked well but, having now entered a load of scores, I find that there are times when the query returns three results for each TxtUnit because two competitors have the same total score. I have modified the table to include the scores for each competition as well as the total so the fields in the table are now:
LngCompetitorNo
TxtUnit
Total
Roupell
Whitehead
What I need is for the query to select the lowest two scores for each unit as before but to eliminate duplicate Total scores by sorting against first, the highest Whitehead score, and next, the highest Roupell score.
Can anyone please help me to sort this one out.
Thanks a lot
John