Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Delete duplicated mysql rows with no primary key
  2. user_id category_id
  3. 1            2
  4. 1            3
  5. 1            4
  6. 1            2
  7. 2            2
  8. 2            3
  9. 2            2
  10.        
  11. CREATE TABLE temp SELECT DISTINCT * FROM tablename;
  12.  ALTER TABLE tablename RENAME junk;
  13.  ALTER TABLE temp RENAME tablename;
  14.        
  15. insert into new_better_table
  16. select user_id, category_id from old_table group by user_id, category_id