Solved

MySQL SQL Command, Reorder

Posted on 2007-03-29
5
889 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now