sql >> Database >  >> RDS >> Mysql

duplicaten in sql verwijderen en de relatietabel dienovereenkomstig aanpassen

begin
  for x in (
            -- find duplicate items
            select *
              from (select rowid row_id,
                           item_id,
                           item_description,
                           row_number() over(partition by item_description order by
                           item_description) row_no
                       from item_tab)
            where row_no > 1) loop
-- replaceing duplicate Items
    update menu_has_item 
    set menu_has_item.item_tab_item_id =
           ( select item_id
              from (select item_id,
                           row_number() over(partition by item_description order by
                           item_description) row_no
                       from item_tab where 
                       item_tab.item_description = x.item_description)
             where row_no = 1)
   where menu_has_item .item_tab_item_id = x.item_id;
-- deleting duplicate items
     delete item_tab where rowid = x.row_id;
  end loop;
-- commit;
end;


  1. Hoe implementeer ik mijn SQL-instructie in Laravel?

  2. FLOOR() Functie in Oracle

  3. Wat is er mis met deze FIRST_VALUE-query?

  4. Null/lege string doorgeven aan Oracle opgeslagen procedure van asp.net