E
E
evilelf2015-12-05 20:50:06
MySQL
evilelf, 2015-12-05 20:50:06

What's wrong with this SQL duplicate removal?

Help correct the request
I want to remove repetitions on the columns post_id, meta_key

DELETE `t1`.* FROM `table` AS `t1`
    LEFT JOIN (SELECT `ID` FROM `table` GROUP BY `post_id`, `meta_key` ORDER BY `ID` DESC) AS `t2` 
        ON `t1`.`ID` = `t2`.`ID`
    WHERE `t2`.`ID` IS NULL ORDER BY `t1`.`ID` DESC;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evilelf, 2015-12-05
@evilelf

Решил сделать вот так. Вроде правильно отработало

CREATE TEMPORARY TABLE `t_temp` 
as  (
   SELECT MAX(ID) as ID
   FROM `table`
   GROUP BY post_id, meta_key
);

DELETE from `table`
WHERE `table`.ID not in (
   SELECT ID FROM t_temp
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question