Guest User

Untitled

a guest
Dec 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. -- MySQL creates a lock on tables during updates, so a temporary table must be used by the inner query within the selection criteria.
  2.  
  3. -- Update Workorder Steps to 'failure_int' datareading_type
  4. UPDATE workorder_steps
  5. SET datareading_type_id = (SELECT id
  6. FROM datareading_types
  7. WHERE code = 'failure_int')
  8. WHERE id IN (SELECT id
  9. FROM (SELECT workorder_steps.id
  10. FROM workorders
  11. INNER JOIN workorder_types
  12. ON workorders.workorder_type_id =
  13. workorder_types.id
  14. AND ( workorder_types.code =
  15. 'compliance'
  16. OR workorder_types.code =
  17. 'sch_compliance' )
  18. INNER JOIN workorder_tasks
  19. ON workorder_tasks.workorder_id =
  20. workorders.id
  21. INNER JOIN workorder_steps
  22. ON workorder_tasks.id =
  23. workorder_steps.workorder_task_id
  24. INNER JOIN datareading_types
  25. ON datareading_types.id =
  26. workorder_steps.datareading_type_id
  27. AND datareading_types.code = 'int') AS wo_step_temp);
  28.  
  29.  
  30. -- Update Steps to 'failure_int' Datareading Type
  31. UPDATE steps
  32. SET datareading_type_id = (SELECT id
  33. FROM datareading_types
  34. WHERE code = 'failure_int')
  35. WHERE id IN (SELECT id
  36. FROM (SELECT steps.id
  37. FROM tasks
  38. INNER JOIN workorder_types
  39. ON workorder_types.id =
  40. tasks.workorder_type_id
  41. AND ( workorder_types.code =
  42. 'compliance'
  43. OR workorder_types.code =
  44. 'sch_compliance' )
  45. INNER JOIN steps
  46. ON steps.task_id = tasks.id
  47. INNER JOIN datareading_types
  48. ON steps.datareading_type_id =
  49. datareading_types.id
  50. AND datareading_types.code = 'int') AS step_temp);
Add Comment
Please, Sign In to add comment