UPDATE `rsp_request_hire_details` as rrhd
INNER JOIN
	`rsp_request_hire` as rrh
	ON rrh.id = rrhd.rsp_rh_id
INNER JOIN
    	`rsp_request_hire_tracking` as rrht
        ON rrht.rsp_rh_id = rrh.id
SET
	rrhd.approved = 0
WHERE rrht.active = 1
AND rrht.status_id = 8;

UPDATE `rsp_request_hire_details` as rrhd
	INNER JOIN
		`rsp_request_hire` as rrh
    	ON rrh.id = rrhd.rsp_rh_id
    INNER JOIN
    	`rsp_request_hire_tracking` as rrht
        ON rrht.rsp_rh_id = rrh.id
SET
	rrhd.approved = 1
WHERE rrht.active = 1
AND rrht.status_id = 7
AND rrhd.approved_request_count > 0;

UPDATE `rsp_request_hire_details` as rrhd
	INNER JOIN
		`rsp_request_hire` as rrh
    	ON rrh.id = rrhd.rsp_rh_id
    INNER JOIN
    	`rsp_request_hire_tracking` as rrht
        ON rrht.rsp_rh_id = rrh.id
SET
	rrhd.approved = 0
WHERE rrhd.approved_request_count = 0;

UPDATE `rsp_request_hire_details` as rrhd
	INNER JOIN
		`rsp_request_hire` as rrh
    	ON rrh.id = rrhd.rsp_rh_id
    INNER JOIN
    	`rsp_request_hire_tracking` as rrht
        ON rrht.rsp_rh_id = rrh.id
SET
	rrhd.approved_request_count = 0
WHERE rrht.active = 1
AND rrht.status_id = 8
AND rrhd.approved_request_count > 0;

UPDATE `rsp_request_hire_details` as rrhd

INNER JOIN rsp_request_hire as rrd
on rrd.id = rrhd.rsp_rh_id

INNER JOIN rsp_request_hire_tracking as rt
ON rt.rsp_rh_id  = rrhd.rsp_rh_id

SET rrhd.approved_request_count = 0

WHERE rrhd.`approved` IS NULL
AND rt.status_id < 7
and rt.active = 1;
