Select X # records of each name in a column

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.
 
M

MGFoster

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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top