Solved

MySQL SQL Command, Reorder

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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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