Guest User

Untitled

a guest
Jan 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. table1
  2. refno status
  3. 1 A
  4. 2 A
  5. 6 A
  6. 3 A
  7.  
  8. table2
  9. refno itemcode qty
  10. 1 1 5
  11. 1 2 0
  12. 3 8 0
  13. 3 1 0
  14. 2 4 3
  15. 6 7 0
  16.  
  17. table1
  18. refno status
  19. 1 A
  20. 2 A
  21.  
  22. table2
  23. refno itemcode qty
  24. 1 1 5
  25. 2 4 3
  26.  
  27. DELETE t1.*, t2.*
  28. FROM Table t1
  29. LEFT JOIN
  30. (
  31. SELECT *
  32. FROM Table2
  33. WHERE qty = 0
  34. ) t2 ON t1.refno = t2.refno
  35. WHERE t2.refno IS NULL
  36.  
  37. delete t1, t2
  38. from table1 t1
  39. left join table2 t2 on t1.refno = t2.refno
  40. where t2.qty = 0 or t2.refno is null;
  41.  
  42. create procedure CleanTable1Table2()
  43. begin
  44. delete from table2 t2
  45. where qty = 0;
  46.  
  47. delete from table1 t1
  48. where not exists (select null from table2 t2
  49. where t2.refno= t1.refno);
  50. end
Add Comment
Please, Sign In to add comment