I want to calculate and update remaining leave days from values found in two different tables (php)

I am working on a leave management system whereby when an administrator creates an account, annual leave days are added by default in the staff table. When a staff member applies for leave days to take and has the leave request approved, I want to subtract the taken days in the leave table from the annual leave days assigned in the staff table, after the subtraction I want to update the staff table annual leave days. I am stuck on how I can join the table, calculate from two different tables’ values, and finally update the staff table leave days. Below is my code:

Staff table

staff_id
firstname
lastname
username
dob
doa
password
leave_days

Leave

leaveid
staffid
date_issued
leave_days_taken
status

approve.php

<?php
session_start();

//Getting leaveid from /leave page
$leaveid = $_GET['leaveid'];

//DB Connection
$conn = mysqli_connect('localhost', 'root', '','leavemanagement');
//If approve button was clicked

//Update the status column
$sql = "UPDATE `leave` SET status = 'Approved' WHERE leaveid = '$leaveid'";
$query = mysqli_query($conn, $sql);

if($query == true){?>
    <script>
        alert("Leave request has been approved");
        window.location.href = 'leave.php';
    </script>
<?php
} else{ ?>
    <script>
        alert("Leave request has not been approved");
        window.location.href = 'leave.php';
    </script>
  <?php  } ?>