UPDATE work_sessions ws
JOIN users u ON u.id = ws.user_id
SET
  ws.company_id = u.company_id,
  ws.session_date = DATE(ws.clock_in_time),
  ws.updated_at = CURRENT_TIMESTAMP
WHERE
  ws.clock_in_time IS NOT NULL
  AND (
    ws.company_id = 0
    OR ws.company_id IS NULL
    OR ws.session_date = '0000-00-00'
    OR ws.session_date IS NULL
  );
