Random record return

I have a DB of sites that I need to query and pull in 5
records that are to be displayed in a random order.
I can limit the records but I'm struggling with displaying
them in a random order.
Any ideas?

We're using MySQL as the DB and to clarify I need to pull in
5 random records in a random order.
I've just been emailed the answer by a friend so I'llpost it
up here.
"SELECT *
FROM tablename
WHERE somefield='something'
ORDER BY RAND() LIMIT 5"
Seems to work fine to me.

Similar Messages

  • Selecting random records out of a table

    Hi,
    I guess this question isn't new, but I didn't found anything about this using the search of this forum.
    How can I get e.g. 5 random records out of a table?
    I have a small table, which stores the special offers of a shop. Let us say, there are 30 records in it. How can I fetch (e.g.) 5 random records of this table?
    I tried to use this statement in a loop:
    SELECT t_item_id FROM tbl_special_offers SAMPLE (1) WHERE ROWNUM = 1
    But this is a very small table, so most of the query returns no data. Additionally I have to check if this number was already selected and ignore it in this case. This isn't a good solution, is it?
    Can somebody help me out with a better solution? Thanks :)

    create or replace package shop_stuff
    is
       function random_number return number;
    end;
    create or replace package body shop_stuff
    is
       function random_number return number
       is
       begin
          return dbms_random.value;
       end;
    begin
       dbms_random.initialize (to_number(to_char(sysdate,'mmddsssss')));
    end;
    create table tbl_special_offers (t_item_id number);
    insert into tbl_special_offers values (1);
    insert into tbl_special_offers values (2);
    insert into tbl_special_offers values (3);
    insert into tbl_special_offers values (4);
    insert into tbl_special_offers values (5);
    insert into tbl_special_offers values (6);
    insert into tbl_special_offers values (7);
    insert into tbl_special_offers values (8);
    insert into tbl_special_offers values (9);
    insert into tbl_special_offers values (10);
    select t_item_id
      from (select t_item_id
              from tbl_special_offers
             order by shop_stuff.random_number)
    where rownum <= 5                       
    SQL> /
    T_ITEM_ID
             6
             7
             5
             4
            10
    SQL> /
    T_ITEM_ID
             1
             5
             3
             9
             6
    SQL> /
    T_ITEM_ID
             6
             5
             3
             2
            10
    SQL> /
    T_ITEM_ID
            10
             2
             8
             4
             1
    SQL>

  • Which system field returns the number of records returned after a select?

    Which system field returns the number of records returned after a select?
    a) sy-index
    b) sy-recno
    c) sy-lncnt
    d) sy-dbcnt
    e) sy-tabix

    Hi,
       SY-DBCNT
    Regards,
    Prashant

  • How can I select the random records in u201Cstep loopu201D.

    Hi, Experts,
    I am using step loop to display the data on screen now I want to select the random records from this step loop display. Like 1st 3rd or 5th record, is there any way to select the records,
    like I did in Table control there was a filed in internal table named marked char length 1, I gave this field name in u201Cw/ SelColumnu201D it fill that field with u2018Xu2019 from where I can get the info about the selected records, in this way I can easily perform the operation on that internal table with the help of that marked field.
    Is there any way to select the records in step loop too ?
    Kind Regards,
    Faisal

    thanks for replay shwetali,
    but i just gave you example of random records with 1st 3rd and 5th my goal is not select only these records. i want to select the random mean any records from the step loop display.
    like we can select from the table control. and when select any record it place 'X' in the given internal table field.
    Thanks and kind Regards,
    Faisal

  • How do I count the number of records returned in the CMIS query

    How do I count the number of records returned in the query CMIS?
    SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
    Euler Homero

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

  • How to e-mail/not e-mail a scheduled report based on records returned

    Hi Everyone,
    Is there a way that there can be logic performed on a report that has been scheduled and ran before it gets sent via e-mail to the end users?  We have scheduled reports that often end up with 0 records returned but users still get the e-mail with the report that contains 0 records.  I would like to e-mail the reports only if the records returned is greater than 0.
    We are on v3.1 so if there is a solution for 3.1 that would be great.  If this capability exists in 4.0, that information would be very helpful as well.
    Thank you for your time.
    David Hellinger

    Apply an event on your report.
    First go to Cmc, create an event based for example on a file that should be created in certain route if the query won't return 0 rows.
    Then apply this event in your report Schedule option Event.

  • How-To Display the Number of Records Returned from a List to the User?

    We currently are using lists to identify accounts that meet various criteria. Because the territories vary from 4k to 60k customers the users have stated that they don't know the size of the list and therefore don't know if they need to refine the list. Currently they are exporting to Excel to look at the row count to see if they need to further refine their searches. This takes quite a while and while shuffling through many lists is a bit painful. Isn't there a way to just show the total records returned from the list down at the bottom of the screen where it allows you to see 25/50/75/100 records at a time?
    There is probably a simple way to do this but it is a large user dissatisfier at the time because we simply don't know how to make this show up. Again we are using lists and not analytics for simple lists at this time.
    - john
    Edited by: user11286597 on Jun 19, 2009 11:02 AM

    Thanks Bobb. I can't believe that one wasn't in R1 :)
    Is there a link to the items being worked in the next release by any chance?
    - john

  • Sequence of records returned

    Hi,
    I have a question on the sequence of records returned by Endeca. I am using Endeca 3.1.1. As I understand the following factors that influence this - order in which records are indexed, relevancy rule / sort rule, boost rule. Now what is the precedence followed by Endeca in applyig the above factors? Does Endeca apply the above factors in the following way or is it different?
    a) order in which records are indexed
    b) boost rule
    c) relevancy / sort rule
    Thanks
    Edited by: 899001 on Apr 15, 2013 8:38 PM

    It depends on the Traversal setting you use
    http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.foldertraversal(v=exchg.80).aspx eg if you only use a Shallow traversal the folders are returned alphabetically. If you use a Deep traversal the you'll get Folder-Subfolder
    alphabetically. The Parent folder will always be returned before the child.
    Cheers
    Glen

  • Periodic Alert-How to send all the records returned from the SQL in a mail?

    Hello all,
    I have defined a Periodic Alert, my SQL query returns more than one record whenever I run it. I also defined an action to send an email with the message consisting of the output variables from the SQL. Whenever i run this alert, a mail is being sent for every single record returned from the query. But i want to send a single mail containing all the records information that my SQL query returns.
    For Example: My SQL query lists all the users created on current date.
    Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
    from fnd_users where trunc(creation_date) = trunc(sysdate)
    Now i want to send a mail with all the users information from the above query, to SYSADMIN. How can this be achieved?
    Thanks & Regards
    chakoo

    Hi Chakoo,
    If the Periodic Alert is not working as requried. You can write a simple package with 3 procedures to implement the writing output to a out file and simultaneuosly send email to multiple receiptents.
    Example:
    Create Package xx_pac
    Create public Procedure P1
    begin
    Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
    from fnd_users where trunc(creation_date) = trunc(sysdate)
    fnd_file.put_line (fnd_file.output, &OUTPUT1, &OUTPUT2);
    end;
    (Create private Procedure P2
    begin
    ---Write the email package using the UTL_SMTP approch. Using this approch you can send the procedure P1 output file as an attachment to the desiginated receiptents.
    end;
    (Create public Procedure P3
    begin
    ---call the procedure P1 using the "g_request_id = fnd_request.submit_request"
    ---Wait for the above procedure to complete using "l_conc_status := fnd_concurrent.wait_for_request" procedure.
    ---call the procedure P2. (When called you must provide the correct to, from address)
    end;
    end;
    Register the Package xx_pac as a concurrent program and schedule when submit it from the request.
    Regards
    Arun Rathod

  • Select Random Records with Group By?

    Hi,
    I currently select random records by using this type of SQL:
    (SELECT *
    FROM ( SELECT *
    FROM ( SELECT *
    FROM TABLEA
    ORDER BY dbms_random.value
    WHERE ROWNUM <= 100
    Based on the following data, I now want to still pick out random records but I only want 1 record from the same ID and START_DATE but where the FLAG could be Y or N.
    So with grouping by ID and START_DATE, I need to still be able to choose the record if it has anything from 1 entry or 10 entries per ID and START_DATE.
    Could this be performed with a GROUP BY?
    ID START_DATE FLAG
    1 12/12/2005 Y
    1 12/12/2005 N
    1 12/12/2005 N
    1 30/12/2005 Y
    1 30/12/2005 N
    1 30/12/2005 N
    2 10/10/2005 Y
    2 07/07/2005 Y
    Thanks for any help.
    Daniel

    Try this [not tested]:
    SELECT *
         FROM
              (SELECT *
                   FROM
                   ( SELECT
                              ID
                             ,START_DATE
                             ,FLAG
                             ,ROW_NUMBER() OVER
                                  (PARTITION BY ID,START_DATE ORDER BY dbms_random.value) RN
                        FROM TABLEA
                   ORDER BY dbms_random.value
         WHERE RN = 1
              AND ROWNUM <= 100
         ;

  • Dynamic Table with Random Records

    What I am trying to do is select random records from a table
    and display them in a dynamic table with max columns set to 3 and
    the 4th record to be on a new row. Below is what I have right now
    and it works to randomly pick records but has no function to set
    columns in a table. If there is an easier way feel free to let me
    know. I have tried various ways to do this but none seem to work.
    <CFQUERY NAME="getItems" DATASOURCE="absi">
    SELECT catfit.*, modcats.*, prodmat.*, prod.* FROM catfit,
    modcats,
    prodmat, prod WHERE prodmat.prodid=catfit.prodid And
    catfit.catid=modcats.catid
    ORDER BY modl ASC </cfquery>
    <cfif getItems.recordCount>
    <cfset showNum = 3>
    <cfif showNum gt getItems.recordCount>
    <cfset showNum = getItems.recordCount>
    </cfif>
    <cfset itemList = "">
    <cfloop from="1" to="#getItems.recordCount#"
    index="i">
    <cfset itemList = ListAppend(itemList, i)>
    </cfloop>
    <cfset randomItems = "">
    <cfset itemCount = ListLen(itemList)>
    <cfloop from="1" to="#itemCount#" index="i">
    <cfset random = ListGetAt(itemList, RandRange(1,
    itemCount))>
    <cfset randomItems = ListAppend(randomItems, random)>
    <cfset itemList = ListDeleteAt(itemList,
    ListFind(itemList, random))>
    <cfset itemCount = ListLen(itemList)>
    </cfloop>
    <cfloop from="1" to="#showNum#" index="i">
    <cfoutput>
    <table width="205" border="0" align="left"
    cellpadding="0" cellspacing="0">
    <tr>
    <td width="235" height="116"> <div
    align="center"><img
    src="../Products/ProductPictures/#getitems.pic[ListGetAt(randomItems,
    i)]#" width="100"></div></td>
    </tr>
    <tr>
    <td
    class="ProdTitle">#getitems.brand[ListGetAt(randomItems,
    i)]# #getitems.modl[ListGetAt(randomItems, i)]#</td>
    </tr>
    <tr>
    <td
    class="paragraph">$#getitems.prc[ListGetAt(randomItems,
    i)]#</td>
    </tr>
    <tr>
    <td><A
    href="../Products/details.cfm?prodid=#getItems.prodid[ListGetAt(randomItems,
    i)]#" class="linkcontact">more
    info</a></td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    </table>
    </cfoutput>
    </cfloop>
    </cfif>

    To start a new row after 3 records, do something like this.
    <table>
    <tr>
    <cfoutput query="something">
    <td>#data#<td>
    <cfif currentrow mod 3 is 0>
    </tr><tr>
    </cfoutput>
    </tr>
    </table>
    You should also know that your approach is very inefficient
    in that you are bringing in to cold fusion more data than you need.
    First of all you are selecting every field from 3 tables when you
    don't appear to be using all of them. Second, you are selecting
    every record and you only want to use 3. There are better ways out
    there, but they are db specific and you did not say what you are
    using.

  • Display Random Record

    Morning all
    Just a quick one.
    How do I display a random record in DW?
    I have a MySQL statement which is:
    SELECT * FROM
    tablename ORDER BY RAND() LIMIT 0,
    number of records to display
    The error message I get is:
    'Syntax error (missing operator) in query expression RAND()
    LIMIT 0'
    If I alter 'RAND()' to 'RND()', I still get the error. If I
    remove the '0' I still get the error.
    Any ideas how to make this work?
    I'm using Access BTW.
    Regards
    Martin

    Tell your SQL statement what to RAND - right now it doesn't
    know how to
    randomize it, by what field.
    "Pantyboy" <[email protected]> wrote in
    message
    news:ef0and$r7g$[email protected]..
    > Morning all
    >
    > Just a quick one.
    >
    > How do I display a random record in DW?
    >
    > I have a MySQL statement which is:
    >
    > SELECT * FROM
    tablename ORDER BY RAND() LIMIT 0,
    number of
    > records to
    > display
    >
    > The error message I get is:
    >
    > 'Syntax error (missing operator) in query expression
    RAND() LIMIT 0'
    >
    > If I alter 'RAND()' to 'RND()', I still get the error.
    If I remove the '0'
    > I
    > still get the error.
    >
    > Any ideas how to make this work?
    >
    > I'm using Access BTW.
    >
    > Regards
    >
    > Martin
    >

  • Random Record Selection

    I have a page that I have a recordset on just calling the
    RecordID in the database. How would I have the page or recordset
    select a random record and put that recordID in say a session
    variable?
    Thanks

    MySQL:
    SELECT yourfield FROM yourtable WHERE ... ORDER BY rand()
    LIMIT 1
    MSSQL:
    SELECT TOP 1 yourfield FROM yourtable WHERE ... ORDER BY
    newid()
    MS Access:
    SELECT TOP 1 yourfield FROM yourtable WHERE ... ORDER BY
    RND(yourprimarykey) [warning: this may not be random through
    CF]
    HTH
    Tim Carley
    www.recfusion.com
    [email protected]

  • Random record for ASP

    I would like to have a section on my ASP page to generate a
    random record that pulls from my database. So that each time the
    page is opened/refreshed, a different record is displayed.
    Any ideas?

    "Biggest Dave" <[email protected]> wrote in
    message
    news:e2nn6n$83e$[email protected]..
    >I would like to have a section on my ASP page to generate
    a random record
    >that pulls from my database. So that each time the page
    is
    >opened/refreshed, a different record is displayed.
    >
    > Any ideas?
    Yes.
    Of course, since I don't know what database you're using, any
    or all of
    those ideas could be useless.

  • Random Record + Update

    Looking to create a random record repeat region where the
    random records being pulled updates a hit count. i.e. a simple
    banner rotator that counts how many times it's displayed. not all
    banners being rotated are in one folder... they are simply accounts
    designated as being featured. I tried the order by rand() limit
    5... error. changed to just rand() and that worked... but how do I
    update a file based on that?

    darrel wrote:
    >> i tried the code you provided, the 2 question
    marks... but that didn't seem
    >> to do it either. anyone else have any ideas on how
    to update a hit counter
    >> based on the random record recordset?
    >
    > Instead of being a smart-***, how about actually either
    a) quoting the
    > original question or b) repeating the question.
    >
    > Anyone that's going to be of any help to you uses the
    newsgroup interface,
    > not the crappy web forum, so when you reply to a
    question that's several
    > weeks/months old, we don't see the original post.
    >
    > So, as such, all we saw was your silly question mark.
    I use a newsreader and saw the entire thread as if it was a
    new one.
    There was 3 days between the original posts and his question
    mark. Maybe
    a question mark wasn't the right way to get more attention to
    the post...
    Steve

Maybe you are looking for

  • Migration of weblogic 8.1 to weblogic 10.3..6

    Hi, We are planning to migrate  application from weblogic 8.1 to weblogic 10.3..6. In weblogic 8 applicaiton was using  simple database authenticator and making use of jars availble in mbeantypes. Could you please let us know whether we can re use sa

  • Issue with CJI3

    Hello, when I am trying to get the report for WBS with the combination of Cost Element. the report is not showing anything. the cost element I am trying to use is of category 21 - internal settlement. I am facing the problem only with the cost elemen

  • GG Monitor

    Hi I have installed Oracle GG monitor on windows machine. The installation went successfully without any error. But while launching the monitor i'm getting below error I Have tried the below solution but no luck tried Solution: Solution : Oracle data

  • HT2623 Why was I forced to move to iCloud, when MobileMe has not been removed?

    Why was I prompted to move to iCloud when MobileMe is still functioning and asking me to subscribe to the site? Am I the only one who is confused? Etela

  • Update termination messages during TECO

    Hi Expert, During TECo of WBS, the followinf messages is coming to SAP inbox and TECO is not not updated in WBS. Could you please send any steps to solve the issue. BR, Update was terminated System ID....   DEV Client.......   220 User.....   Transac