0

Possible Duplicate:
Remove Duplicate Rows Leaving Oldest Row Only?
MySQL remove duplicate rows

Say that I have the following table coolumns: int logicalid(pk) ,int home, int person say the I have the following records...
1,5,6
2,5,6
3,5,5
4,5,5

After my query, I want to place into the new table only one row with the same home,person column values so this will be the output result:
1,5,6
2,5,5
Any ideas??

Community
  • 1
  • 1
user1071420
  • 93
  • 3
  • 11

2 Answers2

1

Create your new table with an auto-increment column for the id.

Then insert into the table, using a query such as:

insert into newTable(home, person)
    select distinct home, person
    from oldTable
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

INSERT INTO newtable(home, person) SELECT DISTINCT home, person FROM sourcetable

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119