Solved

MySQL SQL Command, Reorder

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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