R
R
Roman Sokharev2014-04-28 15:32:58
MySQL
Roman Sokharev, 2014-04-28 15:32:58

Removing Duplicate SQL Rows

I want to remove duplicate lines.
Only the id field (autoincrement) differs.
I tried to make several different "NOT IN" and "NOT EXIST" constructs, but they all give a syntax error. Apparently I'm a shitty requester. What queries do you use to remove duplicates?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2014-04-28
@greabock

DELETE `t1`.* FROM `table` AS `t1`
    LEFT JOIN (SELECT `id` FROM `table` GROUP BY `field1`, `field2`, ...) AS `t2` 
        ON `t1`.`id` = `t2`.`id`
    WHERE `t2`.`id` IS NULL

A
Alexey Skahin, 2014-04-28
@pihel

DELETE FROM tbl WHERE id NOT IN(
  SELECT MAX(id) FROM tbl GROUP BY <поле 1>[,<поле 2>]
)

A
Alexander, 2014-04-28
@SashaSkot

delete from table where id IN (
select id from (
select field, Count(field) as Count
from table
group by field
having count(field)>1) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question