Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    2

    Unanswered: How to sort the table

    I am newbie to MySQL. I wonder if there is a way to sort the table in certain order. It seems to me that "order by" can only be used to sort the query result, not the table itself. How to sort the table itself?

    Many thanks

  2. #2
    Join Date
    Apr 2003
    Location
    Edison, NJ / Oakland, NJ (Work)
    Posts
    32

    Re: How to sort the table

    Originally posted by yhou
    I am newbie to MySQL. I wonder if there is a way to sort the table in certain order. It seems to me that "order by" can only be used to sort the query result, not the table itself. How to sort the table itself?

    Many thanks
    Please anyone out there correct me if I'm wrong, but the way to "order" or "Sort" your tables while they are stored on disk is with Indexes. By creating indexes you allow your data to be found much quicker than if there were no indexing. Here is a page from www.mysql.com about how indexes are treated and created.

    http://www.mysql.com/doc/en/MySQL_indexes.html
    -----------------------------------
    Smith Hayward
    -----------------------------------

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    smith, you're on the right track, but tables are not stored in any order, no matter whether they have indexes or not

    in fact, indexes are stored separately from the tables they index

    even with what's called a clustering index, which mysql doesn't seem to support, you are still not guaranteed to store the rows in any particular order

    besides, it doesn't matter -- you'll never get to see the rows of a table unless you use a SELECT, and if you use a SELECT and want to see the rows in a particular order, then you need to use ORDER BY

    simple, innit


    rudy

  4. #4
    Join Date
    Sep 2002
    Location
    Montreal, Canada
    Posts
    224
    Provided Answers: 1

    Re: How to sort the table

    Originally posted by yhou
    I am newbie to MySQL. I wonder if there is a way to sort the table in certain order. It seems to me that "order by" can only be used to sort the query result, not the table itself. How to sort the table itself?

    Many thanks
    Nope... You have to use ORDER BY to order it... Even if the database would store the rows in order, you would have to dela with updates, deletes and free block inserts... The only way to order is to use ORDER BY...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •