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

  • SEARCH
  • Home
  • 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 7649371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:56:52+00:00 2026-05-31T10:56:52+00:00

I have the following 4 selects: select english,type from table where type=’brief’ ORDER BY

  • 0

I have the following 4 selects:

 select english,type from table where type='brief' ORDER BY RAND() LIMIT 5;
 select english,type from table where type='small' ORDER BY RAND() LIMIT 5;
 select english,type from table where type='medium' ORDER BY RAND() LIMIT 5;
 select english,type from table where type='large';

Rather then making multiple queries I would rather run this as one UNION – also seeing the output from all is in the same format.

I’ve tried the following but the RAND() doesn’t appear to work. There are about 10 options for each type but I keep seeing the same 5 rather then a random return:

 select english,type from table where type='brief' LIMIT 5
 UNION
 select english,type from table where type='small' LIMIT 5
 UNION
 select english,type from table where type='medium' LIMIT 5
 UNION
 select english,type from table where type='large' ORDER BY type,RAND();

Any advise on how to run this UNION with a true random return?

thx

  • 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-05-31T10:56:53+00:00Added an answer on May 31, 2026 at 10:56 am

    If you want to order by the entire union you need to enclose the union in another select like this:

    SELECT (
    select english,type from table where type='brief' LIMIT 5
    UNION
    select english,type from table where type='small' LIMIT 5
    UNION
    select english,type from table where type='medium' LIMIT 5
    UNION
    select english,type from table where type='large'
    )
    ORDER BY type, RAND();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following SQL query that selects some results from my table: select avg(c3),
I have following select results: Select t1.ID, t1.Value1 from t1 where t1.ID=1 Result: ID
I have the following select list from which the user can select multiple values.
I have a table like the following: domainname english www.a.com apples www.a.com peaches www.b.com
I have the following query: SELECT * FROM scool LEFT JOIN people as t1
I have the following query that selects some records from the database: $select_person =
I have the following language table in MySQL to select text in different languages.
I have been struggling with the following query: select * from table_name where contains((field1,field2),'S.E.N.S');
I have got the following exception when try to select data from SQL Server
The following PostgreSQL text search select ID, DISPLAY_NAME, ts_rank_cd(to_tsvector('english', display_name), query) as RANK from

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.