Re: random record with SELECT TOP does NOT work
"Larry Bud" <larrybud2002@y ahoo.comwrote in message
news:1158240460 .638752.239930@ i3g2000cwc.goog legroups.com...
i wasnt thanking you, dumbass.
after all, youre the genius that said:
"heres the real answer:"
SELECT TOP 1 email_address, Rnd(ID) FROM mytable ORDER BY 2
nice guess, but as you are now aware, that couldnt be more wrong (or stupid)
maybe find a new group to offer help in?
"Larry Bud" <larrybud2002@y ahoo.comwrote in message
news:1158240460 .638752.239930@ i3g2000cwc.goog legroups.com...
>
>
>
>
Jimmy wrote:
>
You're unwelcome, jackass.
>
>>
>>
>>
>"Dave Anderson" <NYRUMTPELVWH@s pammotel.comwro te in message
>news:O5Xqh741G HA.4312@TK2MSFT NGP02.phx.gbl.. .
>>
>>
>"Dave Anderson" <NYRUMTPELVWH@s pammotel.comwro te in message
>news:O5Xqh741G HA.4312@TK2MSFT NGP02.phx.gbl.. .
Mike Brind wrote:
>A full and complete explanation of this was provided by Bob
>Barrows very early on in this thread, where he discusses the
>fact that you can't order by an alias in Jet SQL, so you need
>to order by the ordinal position of the calculated column.
>
I generally try to stay out of Access threads, but I have been
following
this one, and I have to ask why anyone even bothers to create a column
for
the random value. It is not required.
>
Working from the tried & true SQL Server favorite...
>
SELECT ... ORDER BY NEWID()
>
...I wondered if the same would work in Access. So I opened a
connection
to the Northwind database and tried:
>
RS = CN.Execute(
"SELECT TOP 1 * FROM Employees " +
"ORDER BY Rnd(EmployeeID* " + -Math.random() + ")"
)
>
This is obviously in JScript, but the principle is the same -- There is
no
need to squabble over the column number, since we do not return the
random
number in a column.
>
This particular example is a poor random generator -- I ran this 10,000
times and got a distribution like this:
>
Record 1 : 100
Record 2 : 122
Record 3 : 1526
Record 4 : 1584
Record 5 : 1302
Record 6 : 1412
Record 7 : 1232
Record 8 : 1487
Record 9 : 1235
>A full and complete explanation of this was provided by Bob
>Barrows very early on in this thread, where he discusses the
>fact that you can't order by an alias in Jet SQL, so you need
>to order by the ordinal position of the calculated column.
>
I generally try to stay out of Access threads, but I have been
following
this one, and I have to ask why anyone even bothers to create a column
for
the random value. It is not required.
>
Working from the tried & true SQL Server favorite...
>
SELECT ... ORDER BY NEWID()
>
...I wondered if the same would work in Access. So I opened a
connection
to the Northwind database and tried:
>
RS = CN.Execute(
"SELECT TOP 1 * FROM Employees " +
"ORDER BY Rnd(EmployeeID* " + -Math.random() + ")"
)
>
This is obviously in JScript, but the principle is the same -- There is
no
need to squabble over the column number, since we do not return the
random
number in a column.
>
This particular example is a poor random generator -- I ran this 10,000
times and got a distribution like this:
>
Record 1 : 100
Record 2 : 122
Record 3 : 1526
Record 4 : 1584
Record 5 : 1302
Record 6 : 1412
Record 7 : 1232
Record 8 : 1487
Record 9 : 1235
>
>
Jimmy wrote:
>now THAT was an intelligent answer from someone who clearly understands
>every piece of the SQL string he provided as an example.
>all of the early posters to this topic were simply pasting something they
>found on a website, not understanding exactly what it was doing, yet
>still
>having the nerve to have a holier than thou attitude!
>>
>thank you!
>every piece of the SQL string he provided as an example.
>all of the early posters to this topic were simply pasting something they
>found on a website, not understanding exactly what it was doing, yet
>still
>having the nerve to have a holier than thou attitude!
>>
>thank you!
You're unwelcome, jackass.
>
after all, youre the genius that said:
"heres the real answer:"
SELECT TOP 1 email_address, Rnd(ID) FROM mytable ORDER BY 2
nice guess, but as you are now aware, that couldnt be more wrong (or stupid)
maybe find a new group to offer help in?
Comment