Hello all,
How can I ramdomly select a list of records from an existing table?
For example: 500,000 names divided by 20,000 samples = 25. The N is
25, meaning samples would be sent to every 25th name on the list.
Any help will be appreciated?
TIA
ja 4 5413
ja <jo******@sbcglobal.net> wrote in
news:2v********************************@4ax.com: Hello all,
How can I ramdomly select a list of records from an existing table?
For example: 500,000 names divided by 20,000 samples = 25. The N is 25, meaning samples would be sent to every 25th name on the list.
Any help will be appreciated?
TIA
ja
If you have a numeric key in the table, use the Modulo operator
SELECT * from mytable where ([NumField] mod 25) = 25;
You'll get every 25th record if NumField contains consecutive
numbers.
--
Bob Quintal
PA is y I've altered my email address.
Bob Quintal wrote: ja <jo******@sbcglobal.net> wrote in news:2v********************************@4ax.com:
Hello all,
How can I ramdomly select a list of records from an existing table?
For example: 500,000 names divided by 20,000 samples = 25. The N is 25, meaning samples would be sent to every 25th name on the list.
Any help will be appreciated?
TIA
ja
If you have a numeric key in the table, use the Modulo operator
SELECT * from mytable where ([NumField] mod 25) = 25;
Shouldn't that be [field] mod 25 = 0 ?
You'll get every 25th record if NumField contains consecutive numbers.
Or create a row counter in a query so it is guaranteed to be sequential....
SELECT A1.Personnel_no, A1.Name, (SELECT COUNT(*) FROM tblEmployee A2 WHERE
A2.NAME <= A1.NAME) AS RowNumber
FROM tblEmployee AS A1
WHERE ((((SELECT COUNT(*) FROM tblEmployee A2 WHERE A2.NAME <= A1.NAME) Mod
25)=0))
ORDER BY A1.Name;
--
regards,
Br@dley
"Br@dley" <no@mail.com.au> wrote in message
news:dt**********@news-02.connect.com.au... Bob Quintal wrote: ja <jo******@sbcglobal.net> wrote in news:2v********************************@4ax.com:
Hello all,
How can I ramdomly select a list of records from an existing table?
For example: 500,000 names divided by 20,000 samples = 25. The N is 25, meaning samples would be sent to every 25th name on the list.
Any help will be appreciated?
TIA
ja
If you have a numeric key in the table, use the Modulo operator
SELECT * from mytable where ([NumField] mod 25) = 25;
Shouldn't that be [field] mod 25 = 0 ?
You'll get every 25th record if NumField contains consecutive numbers.
Or create a row counter in a query so it is guaranteed to be sequential....
SELECT A1.Personnel_no, A1.Name, (SELECT COUNT(*) FROM tblEmployee A2 WHERE A2.NAME <= A1.NAME) AS RowNumber FROM tblEmployee AS A1 WHERE ((((SELECT COUNT(*) FROM tblEmployee A2 WHERE A2.NAME <= A1.NAME) Mod 25)=0)) ORDER BY A1.Name; -- regards,
Br@dley
Two potential problems here are that with 500,000 names (as the OP says)
this is not going to be fast - I could imagine it would pretty much grind to
a halt. Secondly, if you are ordering the people alphabetically and
selecting in any kind of structured way, then the results cannot be said to
be random.
Now I'm not a mathematician, and don't want to enter a huge debate on what
is random, but wouldn't this be better?
SELECT TOP 20000 * FROM People ORDER BY Rnd([ID])
Anthony England wrote: "Br@dley" <no@mail.com.au> wrote in message news:dt**********@news-02.connect.com.au... Bob Quintal wrote: ja <jo******@sbcglobal.net> wrote in news:2v********************************@4ax.com:
Hello all,
How can I ramdomly select a list of records from an existing table?
For example: 500,000 names divided by 20,000 samples = 25. The N is 25, meaning samples would be sent to every 25th name on the list.
Any help will be appreciated?
TIA
ja
If you have a numeric key in the table, use the Modulo operator
SELECT * from mytable where ([NumField] mod 25) = 25; Shouldn't that be [field] mod 25 = 0 ?
You'll get every 25th record if NumField contains consecutive numbers.
Or create a row counter in a query so it is guaranteed to be sequential....
SELECT A1.Personnel_no, A1.Name, (SELECT COUNT(*) FROM tblEmployee A2 WHERE A2.NAME <= A1.NAME) AS RowNumber FROM tblEmployee AS A1 WHERE ((((SELECT COUNT(*) FROM tblEmployee A2 WHERE A2.NAME <= A1.NAME) Mod 25)=0)) ORDER BY A1.Name; -- regards,
Br@dley
Two potential problems here are that with 500,000 names (as the OP says) this is not going to be fast - I could imagine it would pretty much grind to a halt.
Sure. There are lots of ways to skin a cat. The most elegant/complex of SQL
statements may just be too slow realistically.
Secondly, if you are ordering the people alphabetically and selecting in any kind of structured way, then the results cannot be said to be random.
Ah, I missed the random part and only saw the second part (and the subject)
where he stated he wanted every 25th record...
Now I'm not a mathematician, and don't want to enter a huge debate on what is random, but wouldn't this be better? SELECT TOP 20000 * FROM People ORDER BY Rnd([ID])
Yep, that'd be the easiest way to get a random sample.
(I like doing things dynamically so I'd probably pass a parameter such as
the percentage or number of records I wanted returned).
Thanks for pointing that out.
--
regards,
Br@dley This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tcs |
last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't
loaded it yet. I'm still using MS Access. And no, I don't believe this is an
Access question. (But who knows? I...
|
by: (Pete Cresswell) |
last post by:
I've got a .BAT file that I use for executing various MS Access apps that I
wrote way back in the days of 2.0.
It's evolved over time, but it still contains a number of possible paths to...
|
by: Juggernath |
last post by:
Hi,
I spent all morning trying to find a way to select a datetime field from a
table (I work with ASP)
My SQL is "SELECT * FROM Mytbl WHERE myDate = #2.12.2003# "
(I live in Croatia, so that's...
|
by: Bruce |
last post by:
Is there a way to create the "old style" Excel pivot table form in
MSAccess 2002/2003?
I've seen several postings "dancing around this issue", but no
definite answer.
Is there a way to clone the...
|
by: Chris |
last post by:
I recieve unrecognized database format when trying to open a MSAccess
2003 database with MSAccess 2000. I only need it to open as
read-only.
Why won't it open my database?
|
by: Annick Van Hoof |
last post by:
Hi,
I'm having my ASP.NET application hosted at a Windows 2003 server (IIS6).
This works almost all the time (I have uptimes of 100% on most days), but
then all of a sudden a few days in a row I...
|
by: Yelena Varshal via AccessMonster.com |
last post by:
Hello,
I have a problem with one of msaccess.exe API calls that work on my desctop
but does not work on the laptop from within MS ACCESS. There is a lot of
differences between 2 computers...
|
by: reidarT |
last post by:
I am making an installation program for an Access application. The
application is run on both Office 2000, 2002, 2003 and soon 2007 versions of
Office,
When I install the application I need a...
|
by: jdaelhousen |
last post by:
I have a bit of a problem I'm hoping someone can shed some light on...
I have a VB.Net console application written in VS 2003 that produces a .exe file that now sits on a Windows 2000 server...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |