Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make new table with DISTINCT Rows?

Status
Not open for further replies.

kevinforbes

Programmer
Apr 3, 2002
27
0
0
CA
Happy Holidays to all,

I have several tables with several duplicate records - some up to 600 rows when it used to be 200...this is due to someone appending imported data instead of replacing it.

In any case, how do I get one distinct row for each duplicate record and make a new table with it? Also, all of these tables are related, that is why I figure I will recreate all of the tables and then re-create the relationships, make sense?

ex:
tbl1
-----
id -- name -- other
1 -- Joe -- brown hair
1 -- Joe -- brown hair
1 -- Joe -- brown hair

Also, somehow, the primary keys (id in this case) are no longer designated as primary keys...really not sure how this happened...something to do with replication maybe?

Thanks for your help,
Kev
 
SELECT DISTINCT tablename.* INTO newtablename FROM tablename;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top