RE: Can you use random(*) to retrieve a pseudo random r owfrom 3.2.3?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: Can you use random(*) to retrieve a pseudo random r owfrom 3.2.3?

Brandon, Nicholas (UK)

>Nick,
>
>I just thought I should clarify my SQL. The select clause should be
>
>select * from MyTbale join...
>
>since the random number is already included in each row of the joined
>table.

>Dennis Cote

Thanks Dennis for the tip. Did you give it try?

I've tried it and its not selecting any rows after a couple hundred
attempts. I appreciate its "random" but to test I subsequently put in a row
with the min/max random values and that row is still not selected.

CREATE TABLE MyTable(start_col int,end_col int);
INSERT INTO "MyTable" VALUES(-200000000, 200000000);
INSERT INTO "MyTable" VALUES(-2000000001, 2000000001);
INSERT INTO "MyTable" VALUES(-2100000000, 2100000000);
INSERT INTO "MyTable" VALUES(-2147483648, 2147483647);

sqlite> select * from MyTable join (select random(*) as number) as rand
where st
art_col >= rand.number and end_col < rand.number;
sqlite>

Regards
Nick

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Can you use random(*) to retrieve a pseudo random r owfrom 3.2.3?

Jakob Hirsch
Brandon, Nicholas wrote:

> CREATE TABLE MyTable(start_col int,end_col int);
> INSERT INTO "MyTable" VALUES(-200000000, 200000000);
...
> sqlite> select * from MyTable join (select random(*) as number) as rand
> where start_col >= rand.number and end_col < rand.number;

Your logic is broken. As every of your row's start_col is less than
end_row, the result set will be empty for every possible value of
rand.number.
Don't even know what you expected to get with this query.