I have table which has two columns
city_id distance
now i want data to be stored in sequence as i entered it and retrieve it in the same sequence. neither city_id is order nor distance. I have inserted data many times in sequence but when i view the contents of table es the order of rows is changed. anybody can tell me why.
Secondly as i told before both of my columns are unordered so how can i implement indexes on it.previusly i had a third column in it with the name seq_id which was in ordered form but now i m not allowed to use that so i need some other way to do that may be through indexing. how can i do that.[/mysql_man]
about sequence of rows
Moderator: General Moderators
-
bugthefixer
- Forum Contributor
- Posts: 118
- Joined: Mon Mar 22, 2004 2:35 am
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
Even with an index and/or autoincrement column there is no guarantee of the order by which the values are retrieved. You must ORDER BY in you SQL to be 100% sure of that. So either add an autoincrement column and order by that or add a timestamp column and order by that to get the results back in order in which the rows were inserted. Reverse the order by using the DESC attribute to get the newest entries first - i.e.
Select ...
where....
Order by ID DESC
fv
Select ...
where....
Order by ID DESC
fv
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas