Select X # records of each name in a column

  • Thread starter Thread starter Sheryl Scanlon
  • Start date Start date
S

Sheryl Scanlon

I have a table with a name column in it (among others).
There are multiple records for each name (some in the
hundreds) and they all have different numbers of records.
The table has tens of thousands of records.

I need to pull a random sample of 20 records for each name
in the table and put them into a spreadsheet. How do I go
about this query/queries to accomplish this?

When I tried to do it, I could come up with a random
sampling of the whole table, but I couldn't divide it up
to give me 20 of each name.

Thanks for any help you can provide.
 
Sheryl said:
I have a table with a name column in it (among others).
There are multiple records for each name (some in the
hundreds) and they all have different numbers of records.
The table has tens of thousands of records.

I need to pull a random sample of 20 records for each name
in the table and put them into a spreadsheet. How do I go
about this query/queries to accomplish this?

When I tried to do it, I could come up with a random
sampling of the whole table, but I couldn't divide it up
to give me 20 of each name.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use the TOP 20 predicate in the SELECT clause of a subquery. E.g.:

SELECT ...
FROM ...
WHERE some_ID IN (SELECT TOP 20 some_ID FROM ...
WHERE a correlational column = main query column)
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmQ8lIechKqOuFEgEQJVjACg0R1GxNnXvuemQK/jgX5MvFGs1qMAn0Y3
a2Tshv9joEBgCr3imx/ZUNo+
=XDmD
-----END PGP SIGNATURE-----
 
Back
Top