AFAIK, it is impossible to restrict a set of records to unique values if those values exist in more than one record. Each record with "30" is unique - there may be multiple values of 30 but they are still unique and as long as you include other fields you will get multiple iterations of those values. Put another way, if 2 or more records have 30 in a field but there are 2 records with 30 and (e.g.) ID autonumbers, you will get both records for 30. There are only 2 ways I know of to overcome this: create a query with ONLY the field containing the values to be part of the TOP predicate and use that in a second query. Or you can use a subquery, which are not my strong point. As I test case I included those values and autonumber ids, and to eliminate the duplicates using the subquery method I came up with a satisfactory (I think) result. Note that this was covered in my post #8. For the sake doing my own testing I came up with the below results, using the field that I wanted to get the TOP 10 from and one other field - an autonumber id. If you want to include other fields per your last post, adapt accordingly. In my test case it would not matter that I chose the MIN or MAX of id. As long as there are 2 or more records with the Return field value of 30, you will have to decide which of the other fields holds the value you want to retrieve. In the case of autonumber id I'd say it hardly matters if you use the MIN or MAX of ID. You might want to use the min or max of SaleDate.
TABLE
ReturnID |
Return |
1 |
30 |
2 |
30 |
3 |
40 |
4 |
50 |
5 |
50 |
6 |
60 |
7 |
70 |
8 |
80 |
9 |
90 |
10 |
100 |
11 |
100 |
12 |
110 |
13 |
120 |
14 |
120 |
15 |
110 |
SQL
Code:
SELECT tblPodder.return, max(tblPodder.ReturnID) AS maxOfID
FROM (SELECT DISTINCT Return, ReturnID
FROM tblPodder) AS Q
GROUP BY tblPodder.Return;
RESULT
return |
maxOfID |
30 |
2 |
40 |
3 |
50 |
5 |
60 |
6 |
70 |
7 |
80 |
8 |
90 |
9 |
100 |
11 |
110 |
15 |
120 |
14 |
Last edited by Micron; 07-05-2021 at 08:17 PM.
Reason: clarification
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.