0

I need to get the Top 2 records per Customer AND Product. So my data looks like this...

Customer ProdCode
-------- --------
Cust1    PROD1
Cust1    PROD1
Cust1    PROD1
Cust1    PROD1
Cust1    PROD2
Cust1    PROD2
Cust1    PROD2
Cust1    PROD2
Cust1    PROD2
Cust2    PROD1
Cust2    PROD1
Cust2    PROD1
Cust2    PROD1
Cust2    PROD1

but I want it to look like this...

Customer ProdCode
-------- --------
Cust1    PROD1
Cust1    PROD1
Cust1    PROD2
Cust1    PROD2
Cust2    PROD1
Cust2    PROD1

I've found a number of examples of Top N per Group but not for two columns.

HansUp
  • 95,961
  • 11
  • 77
  • 135
petedotg
  • 119
  • 2
  • 4
  • 10
  • 1
    possible duplicate of [selecting top N rows for each group in a table](http://stackoverflow.com/questions/3998529/selecting-top-n-rows-for-each-group-in-a-table) – Joe Jan 23 '12 at 02:50
  • I see it as similar but not a duplicate. I'm trying to do it with two fields from the table, not one... and with access SQL. – petedotg Jan 23 '12 at 03:42
  • This question is similar (and for Access): [complicated-ms-access-greatest-n-per-group-problem](http://stackoverflow.com/questions/1803396/complicated-ms-access-greatest-n-per-group-problem) – ypercubeᵀᴹ Jan 23 '12 at 13:09

1 Answers1

0

You cannot get the displayed result from the data shown. Access provides matches for top N and your data has multiple matches, so these will be returned. It may be possible to get the required result with more realistic data, as there are several workarounds that can force an exact return.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152