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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:38:37+00:00 2026-05-27T17:38:37+00:00

I have a database that has a table that has rows with a value

  • 0

I have a database that has a table that has rows with a value “ID” that changes a lot.
It may be like:


row1.ID = 5,
row2.ID = 47,
row3.ID = -6,
etc.


Completely random order.
Can I make another table when I load a page that will take all of the rows in the first table and create a second table arranging them in order of the “ID” value.
So the second table would be:


row1.ID = -6,
row2.ID = 5,
row3.ID = 47,
etc.


Does that make sense?

  • 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-27T17:38:38+00:00Added an answer on May 27, 2026 at 5:38 pm

    Of course the easiest answer is to use ORDER BY when you query your table, and then you can control the order of rows in the query result set. But I assume you mean you want the “natural” order of rows to be in numeric order when you don’t use ORDER BY.

    If your table uses the InnoDB storage engine, the default order when you query without using ORDER BY is always the order of the primary key. That’s because InnoDB stores tables as a clustered index by primary key. So if ID is your primary key, and you convert your table to InnoDB, then you can rely on its natural order.

    mysql> ALTER TABLE MyTable ENGINE=InnoDB;
    

    If your table is stored as MyISAM, the natural order is the order rows are physical stored in the data file, which has nothing to do with the order of the values or even the order in which you created the rows.

    For these tables, you can dump your table in primary key order with:

    $ mysqldump --order-by-primary databasename tablename > table.sql
    

    Then restore the table. The data will reload in primary key order. Then subsequently the default order when you query without using ORDER BY will be by ID. But this doesn’t prevent the rows from getting out of order again as the values change.


    Re your comments:

    The best option would be to use WHERE. That’s efficient because it can use the clustered index to find the correct row very quickly.

    SELECT * FROM MyTable WHERE ID = 6;
    

    The alternative, which is less efficient but still better than returning all the rows, is to pick some row or rows by their position in the stream, instead of by their value.

    SELECT * FROM MyTable LIMIT 1 OFFSET 5;
    

    The first number is how many rows you want, the second number is how many rows to skip first.

    Normally you’d want to use LIMIT only after specifying an order, otherwise you could get the rows in some meaningless order, and the fifth row wouldn’t be any more desirable than the first row.

    SELECT * FROM MyTable ORDER BY created_at LIMIT 1 OFFSET 5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table message in a database that has almost a million rows.
In my app I have SQLite database that has one table with date rows
I have a relatively large database tables (just under a million rows) that has
I have a SQL database that has a table with a field set to
I have a database table that has a Unique Key constraint defined to avoid
Suppose I have a database table that has a timedate column of the last
I have a database structure that has a Person table which contains fields such
I have a ms access database that has one table for each photo album
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID

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.