Jump to content

Archived

This topic is now archived and is closed to further replies.

nazca

Re-Setting the ID number?

Recommended Posts

I have entered restaurants into my database by city to speed the process up, but when I find another restaurant later and put it with the same city
it comes later and not in-order by name. Since i cannot order by name due to complexities, how can I re-assign the id numbers in my database so that
the restaurants are displayed alphabetically correctly within each city.  I can do a script each time for each city does not bother me.  I want to keep my data of course.  Hope you can help and thanks.

Share this post


Link to post
Share on other sites
one thing that you can do is change the id's to show alfa order. (change the first one that is supposed to be the first alphabetically to 1, the second to 2)

It might take a while, I would try re-thinking your database.

-Chris

Share this post


Link to post
Share on other sites
If the id is an autonumber then DON"T EVEN THINK OF CHANGING IT.  Record ids are something that should be thought of as an intrinsic part of the inner workings of MySQL and nothing to do with how you display the data.  The whole point of a relational database is that you can have table that refer to data in other tables and id is that reference.

Why can't you simply display them in alphabetical order (ORDER by restaurant_name for example)?

Share this post


Link to post
Share on other sites
AndyB is entirely correct -- don't even dream of touching the auto-increment value.  There must be some way to determine the correct order, so you can always do it at run time.

Share this post


Link to post
Share on other sites
it sounds to me like all you need is a multiple-field ordering clause:

[code]ORDER BY restaurant_city ASC, restaurant_name ASC[/code]

this will sort by city first, then among each city, by restaurant name.

(agreed about the importance of leaving a key be)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.