If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to sort the table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-03, 15:47
yhou yhou is offline
Registered User
 
Join Date: Oct 2003
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 11-05-03, 16:30
smithhayward smithhayward is offline
Registered User
 
Join Date: Apr 2003
Location: Edison, NJ / Oakland, NJ (Work)
Posts: 32
Re: How to sort the table

Quote:
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
-----------------------------------
Reply With Quote
  #3 (permalink)  
Old 11-05-03, 20:54
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
Reply With Quote
  #4 (permalink)  
Old 11-05-03, 23:23
bstjean bstjean is offline
Registered User
 
Join Date: Sep 2002
Location: Montreal, Canada
Posts: 219
Re: How to sort the table

Quote:
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...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On