Advertisement
Rochet2

delete rows with duplicate column data

Apr 14th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.61 KB | None | 0 0
  1. -- MAKE A BACKUP OF npc_vendor BEFORE RUNNING
  2.  
  3. SET @FilteredVendorEntry = 600009;
  4.  
  5. -- Add displayid column
  6. ALTER TABLE npc_vendor ADD COLUMN displayid INT UNSIGNED NULL;
  7.  
  8. -- Set correct displays
  9. UPDATE npc_vendor SET displayid = (SELECT displayid FROM item_template WHERE item_template.entry = npc_vendor.item);
  10.  
  11. -- Filter out duplicates leaving the smallest item entry
  12. DELETE a FROM npc_vendor a, npc_vendor b WHERE a.item > b.item AND a.displayid = b.displayid AND a.entry = @FilteredVendorEntry AND b.entry = @FilteredVendorEntry;
  13.  
  14. -- Drop the displayid column
  15. ALTER TABLE npc_vendor DROP COLUMN displayid;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement