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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:29:27+00:00 2026-06-03T02:29:27+00:00

I have a mysql table with only one column, the column has got some

  • 0

I have a mysql table with only one column, the column has got some 3 letter words and some 4 letter words, and some 5 and 6 letter words.

I want a query to at first select randomly from all 3 letter words, when they’re all gone, then move on to 4 letter words, and so on.

This is my query:

SELECT `word` FROM `words` ORDER BY LENGTH(`word`) ASC, RAND() LIMIT 1

This works as expected so far in the few times I’ve tried, but I’d like to be sure that it’ll always work like this.

  • 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-03T02:29:28+00:00Added an answer on June 3, 2026 at 2:29 am

    Your query looks fine to me, but I hope the table is small because MySQL will be scanning all the rows every time and then using filesort, all to return a single row.

    Adding a wordlength column and indexing it will not improve the query because the ORDER BY RAND() function would invalidate use of the index.

    Consider splitting the words up into separate tables, depending on their length, at least you’ll only be scanning all rows for words of the same length. Select from the three_letter_words table first, and if there are no results, then select from the four_letter_words table, and so on.

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

Sidebar

Related Questions

Say I have a mysql table of names and one column has the following
I have a MySQL table that will only have one row. What should my
I have mysql table that has a column that stores xml as a string.
I have a server table which has a column named 'SN' in mysql, when
I am using mysql 5.0.51b. I have one table named xyz. xyz table has
I have a ~100GB MySQL table with nearly 1 billion rows. It only has
I have a MySQL table with approximately 3000 rows per user. One of the
I have a MySQL table with a column of well-formed URLs. I'd like to
I have a MySQL table using the UTF-8 character set with a single column
I have a Mysql table where it combines three tables. This table stores some

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.