oracle - SQL return n rows per row value -


greetings sql people of nations.

simple question, simple answer.

i have oracle database table persons' information. columns are:

firstname, lastname, birthdate, birthcountry 

let's in table have 1500 persons born in aruba (birthcountry = "aruba"), 678 botswanans (birthcountry = "botswana"), 13338 canadians (birthcountry = "canadia").

what query need write extract sample batch of 10 records each country? doesn't matter 10, long there 10.

this 1 query output 30 rows, 10 rows each birthcountry.

this select 10 youngest people each country:

select  *    (         select  p.*,                 row_number() on (partition birthcountry order birthdate desc) rn            persons p         )   rn <= 10 

Comments