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 9130275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:56:06+00:00 2026-06-17T07:56:06+00:00

I want to retrieve random rows from table but this rows must be order

  • 0

I want to retrieve random rows from table but this rows must be order in category.

select category, 
   (select order_number 
   from orders 
   where order_number in (123,125,128,129,256,263,966,258,264,159,786) 
   order by rand()) 
from orders 
order by category

This is the query I tried. But that retrieves whole data in table.


Worked query ;

SELECT category,order_number FROM (
    SELECT category,order_number 
    from orders 
    where order_number in (`$order_numbers_variable`) 
    order by rand()
) order by category
  • 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-17T07:56:07+00:00Added an answer on June 17, 2026 at 7:56 am

    I assume the requirement is:
    Retrieve ‘N’ random rows from a table sorted by ‘category’.

    Lets assume N is 10. If you want to change the number of rows, then change it in the LIMIT clause.

    SELECT * FROM (
        SELECT category from orders ORDER BY rand() ASC  LIMIT 10
    ) AS innerResult 
    ORDER BY innerResult.category
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table as follows. I want retrieve row values from this
i want to retrieve 15 records from a table of around 50 records. but
I want to retrieve website title from webview cookies of my application. I am
I want to retrieve the DOM path of a random element in a website
I want to pick a random picture from: http://9gag.com/top/all/index/page/1?view=json To display it properly i
Possible Duplicate: SQL Server Random Sort I guess it sounds stupid but I want
I have a situation where I want to order a column from the highest
I have about 10,000 products in the product table. I want to retrieve one
This question on getting random values from a finite set got me thinking... It's
I have a query which aims to retrieve a random row from a result

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.