1

Possible Duplicate:
MySQL Duplicate rows
how to delete duplicate rows from a table in mysql

I have data that looks something along the lines of:

22205 | 2179 |  85 
 8306 | 2179 | 178
11164 | 2179 | 178
23873 | 2179 | 178
 8308 | 2179 | 314
22203 | 2179 | 314
22201 | 2178 |  85

I'm trying to figure out a query that will let me remove the duplicates of the third column. As in we should only have one 178 and one 314. But keeping in mind that it can duplicate as long as the second column doesn't duplicate so final result should look like:

22205 | 2179 |  85 
 8306 | 2179 | 178
22203 | 2179 | 314
22201 | 2178 |  85

Can anyone help?

Community
  • 1
  • 1
Peter
  • 3,144
  • 11
  • 37
  • 56

2 Answers2

2

Simply use GROUP BY (example):

SELECT *
FROM `Table1`
GROUP BY `b`, `c`

Assuming:

CREATE TABLE Table1
    (`a` int, `b` int, `c` int);

INSERT INTO Table1
    (`a`, `b`, `c`)
VALUES
    (22205, 2179, 85),
    (8306, 2179, 178),
    (11164, 2179, 178),
    (23873, 2179, 178),
    (8308, 2179, 314),
    (22203, 2179, 314),
    (22201, 2178, 85);
0b10011
  • 18,397
  • 4
  • 65
  • 86
0

Maybe you need to create a composite key on both columns. Create a new temp table lets say 'tbl_temp' then copy over all rows using INSERT iGNORE ...

Sabeen Malik
  • 10,816
  • 4
  • 33
  • 50