Solved

MySQL SQL Command, Reorder

Posted on 2007-03-29
5
892 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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