Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:04:07+00:00 2026-06-08T09:04:07+00:00

I am thinking of returning a randomly ordered SQL response where the results are

  • 0

I am thinking of returning a randomly ordered SQL response where the results are mixed up randomly, with a limit.
The thing is I need All the rows back, basically divided into groups (chunks of rows). I hope I am clear.

For example, from table A:

ID   |   NAME    |   PROFESSION
++++++++++++++++++++++++++++++++
1    |  Jack     |   Carpenter
2    |  Rob      |   Manager
3    |  Phil     |   Driver
4    |  Mary     |   Cook
5    |  Tim      |   Postman
6    |  Bob      |   Programmer

The query would return something like this:

With a limit of 0,2:

6    |  Bob      |   Programmer
4    |  Mary     |   Cook

With a limit of 2,2:

1    |  Jack     |   Carpenter
5    |  Tim      |   Postman

With a limit of 4,2:

3    |  Phil     |   Driver
2    |  Rob      |   Manager

Note: all the table rows were returned. In my page I need to have a << >> buttons that will show the user the needed “group”s of data.
How do I go about writing such a query ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:04:08+00:00Added an answer on June 8, 2026 at 9:04 am

    A better name for your explained problem would be randomly shuffled records. That is true that the order is random but since the order needs to be remembered, you have no choice but to save it in a column. You can do this by saving a randomly populated field and ordering your records based on that. This way you have ordered your records in no specific order while the order is remembered for future select queries. And whenever you got tired of the order, you can update the mentioned field with new randomly generated values to shuffle them again. This is the technique used by players to shuffle a playlist without replaying a song twice.

    [EDIT]

    While the first given solution stands as the general answer, there’s a hack you can use in MySQL to randomly order records. In this way, all you need to store for remembering an order is its seed.

    SELECT * FROM tbl ORDER BY RAND(s);
    

    For instance, if you want each user see the records in some different randomly ordered, you can use their user_id as the seed. This way the order each user will ever see the records in, will remain the same while it is random and different from other users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thinking about if we modify the definition of Hamiltonian path as we need to
When I write SQL queries, I find myself often thinking that there's no way
I'm thinking of returning errors that ocurred inside a model, the following way: class
An AJAX call is returning a response text that includes a JSON string. I
I am using this query to get all the data but I also need
I have a SQL query that is returning a table like the following: id
I´ve lately been thinking about the things i´m returning from methods and I noticed
When I run a query which returns millions of rows from within Sql Management
Thinking about avoiding code replication, I got a question that catches me every time
Thinking that the answer to this is pretty obvious but here it goes: When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.