Results 1 to 3 of 3
  1. #1
    warrenk is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    3

    Random Record Within Group

    I know I can get a random record using:

    select top 1 * from yourtable order by rnd(id)

    What I need to do is pick a random record within a group:

    Example:



    I would like to pick 3 random records (one in each group). How can I do this?

    ID Group
    1 A
    2 A
    3 A
    4 B
    5 B
    6 B
    7 C
    8 C
    9 C

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Try something like this -
    Code:
      SELECT T0.MyGroup, T1.MyID
      FROM MyTable AS T0,
           (SELECT TOP 1
            T1.MyID, T1.NewRandom(MyID)
            FROM MyTable
            WHERE T0.MyGroup = T1.MyGroup
            ORDER BY NewRandom(MyID));
    NewRandom is posted here - https://www.accessforums.net/queries...der-38336.html
    It goes in a standard module.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-09-2013, 06:31 PM
  2. Display random record with button
    By shredsec in forum Forms
    Replies: 3
    Last Post: 01-01-2013, 02:27 AM
  3. Replies: 1
    Last Post: 12-05-2011, 03:26 PM
  4. Random Record pull
    By Madmax in forum Access
    Replies: 2
    Last Post: 06-28-2011, 08:26 PM
  5. random record
    By wasim_sono in forum Programming
    Replies: 1
    Last Post: 02-06-2008, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums