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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:23:22+00:00 2026-05-16T00:23:22+00:00

i have a mysql db with a table ‘difficulties’ with a few records. If

  • 0

i have a mysql db with a table ‘difficulties’ with a few records. If i do “select * from difficulties” i get them back in the order they were added, ordered by primary key id:

mysql> select * from difficulties;
+----+-------+-----------+--------+----------+-----------+
| id | value | name      | letter | low_band | high_band |
+----+-------+-----------+--------+----------+-----------+
|  1 |     1 | very_easy | VE     |        1 |         1 | 
|  2 |     2 | easy      | E      |        2 |         5 | 
|  3 |     3 | medium    | M      |        6 |        10 | 
|  4 |     4 | hard      | H      |       11 |        12 | 
|  5 |     0 | na        | NA     |        0 |         0 | 
+----+-------+-----------+--------+----------+-----------+

However, if i do “select name from difficulties” i get them back in a different order:

mysql> select name from difficulties;
+-----------+
| name      |
+-----------+
| easy      | 
| hard      | 
| medium    | 
| na        | 
| very_easy | 
+-----------+

My question is: what determines this order? Is there any logic to it? Is it something like “the order the files representing the records happen to be in within the filesystem” or something else that is to all intents and purposes random?

thanks, max

  • 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-16T00:23:23+00:00Added an answer on May 16, 2026 at 12:23 am

    This is correct and by design: if you don’t ask for sorting, the server doesn’t bother with sorting (sorting can be an expensive operation), and it will return the rows in whatever order it sees fit. Without a requested order, the way the records are ordered can even differ from one query to the next (although that’s not too likely).

    The order is definitely not random – it’s just whatever way the rows come out of the query, and as you see, even minor modifications can change this un-order significantly. This “undefined” ordering is implementation dependent, unpredictable and should not be relied upon.

    If you want the elements to be ordered, use the ORDER BY clause (that’s its purpose) – e.g.

    SELECT name FROM difficulties ORDER BY name ASC;
    

    That will always return the result sorted by name, in ascending order. Or, if you want them ordered by the primary key, last on top, use:

    SELECT name FROM difficulties ORDER BY id DESC;
    

    You can even sort by function – if you actually want random order, do this (caveat: horrible performance with largish tables):

    SELECT name FROM difficulties ORDER BY RAND();
    

    For more details see this tutorial and the documentation.

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

Sidebar

Related Questions

I have a MySQL table and I am looking to create a stats page
I have a MySQL table. Let's call it Widgets. The Widget table has 3
I have a mysql table with entries like this: id name value date 1
I have a MySQL table with about 1000 rows, filled with different types of
I have a mysql table with contents the structure is here: I want to
I have a mysql table and data entries in it: CREATE TABLE `invoices`.`invoices` (
I have a mysql table containing 400,000 rows whenever I run a PHP script
I have a mysql table with users and their weekly calendar. Every user can
I have a MySQL table with 2 fields: pd_code and pd_sort (pd_sort default value=0).
I have a MySQL table ( members ) with six columns ( FirstName, LastName,

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.