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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:40:56+00:00 2026-05-23T20:40:56+00:00

I want use ORDER BY RAND() query mysql. But I have some question want

  • 0

I want use ORDER BY RAND() query mysql. But I have some question want to ask.

my mysql table ‘image’ like:

id | image | width | height |
1  | 1.jpg | 640   | 480    |
2  | 2.jpg | 800   | 600    |
3  | 3.jpg | 480   | 600    |
4  | 4.jpg | 720   | 480    |
5  | 5.jpg | 600   | 800    |
6  | 6.jpg | 1024  | 768    |
7  | 7.jpg | 768   | 1024   |
8  | 8.jpg | 800   | 600    |
9  | 9.jpg | 720   | 560    |
10 | 10.jpg| 800   | 600    |

I need do a mysql query ORDER BY RAND() print 5 images, the orders are:

first: width >= 720 and height >= 560 , 1 image(this may be width < height)

second: width > height, 2 images.(left the first 1 image, do the rest 9 images ORDER BY RAND())

third: width >= 640, 2 images.(left above 3 images, do the rest 7 images ORDER BY RAND())

all the 5 images no repeat. My mind are confused now, need a help.

  • 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-23T20:40:58+00:00Added an answer on May 23, 2026 at 8:40 pm

    Well, if I understand your question correctly you want to do something like

    (SELECT image FROM tab WHERE(first) ORDER BY RAND() LIMIT 1)
    UNION
    (SELECT image FROM tab WHERE(second) ORDER BY RAND() LIMIT 2)
    UNION
    (SELECT image FROM tab WHERE(third) ORDER BY RAND() LIMIT 2)
    

    In the each WHERE clause replace the first, second and third with correct constraints…

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

Sidebar

Related Questions

I have never used CRON before but I want to use CRON in order
I want to use order by with union in mysql query. I am fetching
i want use some data from a website with web service. i have a
I have this code which i want to use in order to access a
I want to use multiple order by in my query, and i am using
I have the following models associations which I want to use in order to
I want to use ORDER BY clause in functions of SQL Server. But I
i want to use the order by catid... but i need to use it
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want to use all the photos in a Flickr set and in order

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.