#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Order entry problem


    Hi everybody,
    I have a MyIsam DB and one of my tables gives me the following problem:
    The order of the entry is visualize by default by descenting order whilst is should not.
    To details:
    This is the description of the table:
    +-------------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------+--------------+------+-----+---------+----------------+
    | id_voice | int(11) | NO | PRI | NULL | auto_increment |
    | id_project | int(11) | YES | | 0 | |
    | description | varchar(255) | NO | | NULL | |
    +-------------+--------------+------+-----+---------+----------------+

    This is as it is
    +----------+------------+-------------+
    | id_voice | id_project | description |
    +----------+------------+-------------+
    | 4 | 1 | OTHER |
    | 3 | 1 | MNG |
    | 2 | 1 | DEMO |
    | 1 | 1 | RTD |
    +----------+------------+-------------+

    As it should be
    +----------+------------+-------------+
    | id_voice | id_project | description |
    +----------+------------+-------------+
    | 1 | 1 | RTD |
    | 2 | 1 | DEMO |
    | 3 | 1 | MNG |
    | 4 | 1 | OTHER |
    +----------+------------+-------------+

    May anybody explain be this?
    There no motivation thus it should happen in my opinion.

    Thanks
    Claudia
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    157
    Rep Power
    89
    What is the syntax of the query you are running?
  4. #3
  5. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    Hi,

    MySQL tables aren't ordered by default. Tables in the relational database model are mathematical sets, so there is no order. Well, the rows are of course displayed one after another, but that's arbitrary.

    If you want to sort the rows in a specific way, you have to add an ORDER BY clause to your SELECT query:

    Code:
    SELECT
    	`id_voice`
    	, `id_project`
    	, `description`
    FROM
    	`yourtable`
    ORDER BY
    	`id_voice` ASC
    ;
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    When I do the query to extract data, I order by id_voice but this is weird as well.
    Let's suppose I insert a new entry.
    This is put as first in the list, while in many other tables of my db is put as last.
    If the tables are "identical" why does it happen for a specific table?

    @TASB do you mean insert query?

    Thanks
  8. #5
  9. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    Originally Posted by claudia23
    When I do the query to extract data, I order by id_voice but this is weird as well.
    What's weird?



    Originally Posted by claudia23
    Let's suppose I insert a new entry.
    This is put as first in the list, while in many other tables of my db is put as last.
    If the tables are "identical" why does it happen for a specific table?
    You haven't understood what I said. Tables in MySQL have no order. They are not lists, and new rows are not inserted at a specific place.

    You probably think that because you're using a user interface like phpmyadmin to view your tables. But what this application actually does is perform a SELECT without an ORDER BY clause, so that the rows are displayed in some random order. This is not how the table is structured. The table is an unordered collection. When you want a specific order, you have to add an ORDER BY clause (you can do that in phpmyadmin by clicking on the specific column).

    Again: Tables in the relational model have no order. They are just a heap of rows.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Thanks everybody for the explanation.
    My doubts were due to the fact I am use to visualize tables in a certain way and I was scared there was a problem in my Mysql version or something similar.
    If you think that everything, I will sleep quite tonight.

    Claudia

IMN logo majestic logo threadwatch logo seochat tools logo