问题
In my activity_logs
, it contains columns: material_name
, user_id
, mod_result
(this marks a test if Pass/Fail), cert_links
. Somehow the users generate twice the entry of the material_name
with the cert_links
column left blank.
I can list duplicates to all user_id
with:
SELECT user_id, material_name, mod_score, cert_links, start_time
FROM activity_logs
WHERE mod_result = 'Pass' AND cert_links = ''
I want to delete the duplicate entries that has mod_result = 'Fail'
and cert_links = ''
回答1:
you can use:
Delete from activity_logs WHERE mod_result = 'Fail' AND cert_links = '' or ''NULL'
回答2:
3 steps:
Step 1: Move the non duplicates (unique tuples) into a temporary table
CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1 GROUP BY [COLUMN TO remove duplicates BY];
Step 2: delete the old table
DROP TABLE old_table;
Step 3: rename the new_table to the name of the old_table
RENAME TABLE new_table TO old_table;
来源:https://stackoverflow.com/questions/22004725/deleting-duplicates-of-tables