SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)

    query to get random record from every n number of records in mysql

    Hi All,

    I have got a situation where i need to get records from database in such a way that, the records should be random form every given N number of records.

    Let me explain with example
    If the given N be 10 and total records in table be 100 then
    i need to fetch one random record from every 10 records present in the table
    so total i need 10 records in a way that
    1st record from 1-10 records
    2nd from 11-20 records
    3rd from 21-30
    10th from 91-100

    Is it possible to get?
    Please give me some solution.
    Thanks in advance

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    the problem with your problem is that the rows in a table aren't stored in any particular order

    so to get a random row from rows 1-10 means you have to first sort the rows into whatever order you expect, so that you can identify rows 1-10 | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Tags for this Thread


Posting Permissions

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