SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 1999
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ouch.

    I hate to ask two questions in one day; makes me look dumb, but I have no choice here.

    As the subject states, what I want to do is sort a MYSQL table so that the rows are re-arranged by the ID_NUM column which is ranges basically from 1 to 10. I figure this probably causes strain on the server, but since this is an update program that I only use, I figure it won't mean anything. For my particular task, it would be much easier for me if the column was 1-2-3-4-5-6 instead of 1-3-4-5-2-6

    If it helps, this particular table will only carry 10 records at all times. No less, no more. Also the column ID_NUM is set as my primary key.

  2. #2
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I undestand right it would be like this:

    select whatever, somthing from sometable order by ID_NUM

    Add the bolded part to the end of your mySQL query but before your limit statment (if you have one). It should order them by the id like this:

    1-2-3-4-5-6-7-8-9-10

    Try this to put the from greatest to least:

    select whatever, somthing from sometable order by ID_NUM desc

    That would order them like this:

    10-9-8-7-6-5-4-3-2-1

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 1999
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Justin,

    This is exactly what I had in mind, expect for one factor.

    This simple changes the output to be ordered.
    How would I make it so that they actually records are sorted like such on the table?

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Canuk,

    The short answer is that you can't - and you don't want to Its none of your business how the RDMS goes about physically arranging and storing the data. Physical database management is a black science and involves all sorts of considerations which include things such as "page sizes" and hashing algorithms - things that I know nothing about. It's logical to assume that a RDMS stores data in an ordered manner - but this is not the case. This is actually an inefficient way to store data!

    That's the great thing about relational database managment systems (RDMS) - they provide a nice layer of abstraction. You put your data in, update, and query the database with SQL. You don't have to know or worry about how the data is physically being stored on the hard disk.

    Here are some links to threads where I have made similar comments on this topic:
    http://www.sitepointforums.com/showt...ing#post120387
    http://www.sitepointforums.com/showt...153#post119153


Bookmarks

Posting Permissions

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