mysql - How Do I delete these orphan records from my Table, Iteratively? -


i have 2 tables

  1. words(word_id, value);
  2. word_map(sno(auto_inc), wm_id, service_id, word_id, base_id, root_id);

    • in sno auto incremented indexing.

    • wm_id actual id unique each service (serviceid, wm_id form unique key).

    • base_id , root_id referenced wm_id i.e., store values of respective wm_id of new word being inserted.

my requirement want delete records table where, words's base_id or root_id not exists in table

for example,

a new word tr_id = 4, base_id = 2 , root_id = 1 there must 2 other records tr_id s 2 , 1 if not can call orphan , record wm_id = 4 must deleted, records other wm_ids having 4 base_id or root_id must deleted r orphans if 4 gets deleted , on.

can suggest me solution problem.

what tried:

i tried write procedure using while in has query like,

delete words_map base_id not in (select wm_id words_map) or root_id not in (select wm_id words_map) deleting/ or updating on same table using kind of nested queries not possible, searching alternate way.

what doubt :

  • i thought of reading these wm_ids array reading 1 one deleting based on that, dont think have arrays in stored procedures.

  • is cursor alternative sitution.

  • or other best solution problem.

edit 1: please go through http://sqlfiddle.com/#!2/a4b6f/15 clear experimental data

any , appreciated


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -