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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:17+00:00 2026-05-27T16:43:17+00:00

Possible Duplicate: Default sort-ordering in MySQL (ALTER TABLE … ORDER BY …;) I have

  • 0

Possible Duplicate:
Default sort-ordering in MySQL (ALTER TABLE … ORDER BY …;)

I have a table like this:

CREATE TABLE IF NOT EXISTS `table_test` (
  `id` mediumint(8) unsigned NOT NULL,
  `country` enum('AF','AX','AL') DEFAULT NULL,
  `number` tinyint(3) unsigned DEFAULT NULL,
  `sort_order` double unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `country` (`country`),
  KEY `id` (`id`,`country`)
) ENGINE=MEMORY DEFAULT CHARSET=latin1;

I have a table for which I changed the default ordering like:

ALTER TABLE test_table ORDER BY sort_order ASC;

This table is never updated and no records are removed or added during its life. This all seems to work so if I use the folowwing query:

SELECT * FROM test_table LIMIT 10

It returns the 10 records in the right order.

And even if I use:

SELECT * FROM test_table WHERE num=3

it returns the results in the right order.

But if I do

SELECT * FROM test_table WHERE country='AX'

It will return the results in reversed order.

Can someone tell me how this can happen?

  • 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-27T16:43:17+00:00Added an answer on May 27, 2026 at 4:43 pm

    Specifying the ORDER BY on a table is just a help for the engine to speed up queries with the same order. It will not force mysql to always return the result with the same ordering.

    Described in this: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

    “ORDER BY enables you to create the new table with the rows in a specific order. Note that the table does not remain in this order after inserts and deletes. This option is useful primarily when you know that you are mostly to query the rows in a certain order most of the time. By using this option after major changes to the table, you might be able to get higher performance. In some cases, it might make sorting easier for MySQL if the table is in order by the column that you want to order it by later. “

    So you must use the ORDER BY expression in your queries too.

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

Sidebar

Related Questions

Possible Duplicate: break in a case with return.. and for default If I have
Possible Duplicate: .Net Process.Start default directory? I have a C# application, mono to be
Possible Duplicate: Is it possible to skip parameters that have default values in a
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Edit: This has nothing
Possible Duplicate: Stop default hashtag behavior with jquery I have some jquery code on
Possible Duplicate: How do you set a default value for a MySQL Datetime column?
Possible Duplicate: C# Lambda ( => ) For instance Messenger.Default.Register<AboutToCloseMessage>(this, (msg) => { if
Possible Duplicate: What is the default value of Result in Delphi Similar to this
Possible Duplicate: How do you give a C# Auto-Property a default value? I have
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument This is very odd,

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.