Solved

MySQL SQL Command, Reorder

Posted on 2007-03-29
5
891 Views
Last Modified: 2008-09-08
I have a MySQL database.  If possible, I'd like 1 SQL Command to do this.  The id's on it are all jumbled up and I would like to keep the order that the records are in the database, but change the id's so that they are consecutive.  eg

now - (1,a)(3,b),(4,c),(6,d),(8,e),(9,f)

after - (1,a),(2,b),(3,c),(4,d),(5,e),(6,f)

Thanks.
0
Comment
Question by:smoothcat11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
wakemup earned 250 total points
ID: 18818432
How about 3 statements?

create temporary table temp (id int not null primary key auto_increment, data varchar(255)) select null, data from _template;
select * from temp;
drop table temp;

You can probably leave the drop table out if the connection is closed before you call the sql again.
0
 
LVL 2

Expert Comment

by:wakemup
ID: 18818439
You may want to add an order by to the select for the data you wish to have in sequence too.
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 250 total points
ID: 18818594
this seems a silly request as your table will presumably again have holes in it after sometime

why do you want this sequence to be stored?

its much better to calculate the "order" for the conditions you need to select by             at the time of
rubbibng the select query...

 
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question