Link to home
Start Free TrialLog in
Avatar of DrDamnit
DrDamnitFlag for United States of America

asked on

SELECT DISTINCT / Add auto_increment field

I have a table:

CREATE TABLE `asdf` (
  `asdf` int(10) unsigned NOT NULL auto_increment,
  `sdfg` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`asdf`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

Whereby I use CREATE TABLE tmp SELECT DISTINCT sdfg FROM asdf; to eliminate duplicates.
Then I drop the original table, asdf, and rename tmp to asdf.

So the duplicates are gone. My question is this:

How do I add a field to this table that is of type UNSIGNED INT, AUTO_INCREMENT, and is the PRIMARY KEY of the table, AND... that numbers each record in the table starting at 1?
ASKER CERTIFIED SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DrDamnit

ASKER

When I create the auto_increment column, will it number the existing records automatically?
Yes.