Results 1 to 4 of 4

Thread: Random

  1. #1
    Join Date
    Feb 2004
    Posts
    16

    Unhappy Unanswered: Random

    Is there a select Random command that i can use ??

    say i have 8 rows in my Top_Res table

    how do i randomly select one of them in SQL ??

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Random

    Yes, you can use DBMS_RANDOM.VALUE:

    select ename from
    ( select ename from emp order by dbms_random.value )
    where rownum = 1;

  3. #3
    Join Date
    Feb 2004
    Posts
    16

    Re: Random

    so if i have the table Top_Res

    and it contans:

    Topic_Result_ID, Topic_Result_Counter
    ID1, 1
    ID2, 1
    ID3, 1

    MY CODE WOULD LOOK LIKE THIS ?

    select ename from
    ( select ename from Top_Res order by dbms_random.value )
    where rownum = 1;

    Is this right ?

    sorry to ask so many questions

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Random

    Yes - but you change "ename" to whatever columns you want to select!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •