I have a table that includes ID, person's name, and then some other data. I'm trying to write a query that returns only 10 rows for each person (ideally 10 random rows, but if it has to be the first 10 rows for each person, that would suffice). I've found SQL to return 10 random rows from the table, but not 10 rows per person. This tells how to solve it in Oracle, but I'm having trouble making that work in Access: SQL return n rows per row value
select *
from (
select row_number() over (partition by BirthCountry
order by dbms_random.value) as rn
, FirstName
, LastName
, BirthDate
, BirthCountry
from YourTable
)
where rn <= 10
EDIT: I have now tried this based on the link posted to the comments, and it only returns one record (for the person who just has one record in the table--all the others would have more than 10).
SELECT a.ID, a.mapped_prov_name, Count(*) AS rank_number
FROM qryJustNames AS a
INNER JOIN qryJustNames AS b ON a.mapped_prov_name = b.mapped_prov_name
GROUP BY a.ID, a.mapped_prov_name
HAVING COUNT(*) <= 10
ORDER BY a.mapped_prov_name