Db2 for z/OS & Db2ZAI

Db2 for z/OS and its ecosystem

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only

Help Request: How to Retrieve all rows matching a WHERE clause, but in "random" order

  • 1.  Help Request: How to Retrieve all rows matching a WHERE clause, but in "random" order

    Posted 4 hours ago

    I have a requirement to perform an action against a subset of rows in a DB2 table, i.e. not all rows, but only those that match a WHERE clause. The requirement is to retrieve all of the rows that match the WHERE clause, but in a "random" order. I am thinking I can use a statement like the following

    DECLARE RANDOM_CURSOR FOR

    SELECT rand() as idx, <and other columns)

    WHERE ...

    ORDER BY idx 

    Will this work?

    And do I have to SELECT rand(), and if so, what is its datatype?



    ------------------------------
    Curt Gilker
    ------------------------------