Another Solution to the Excercise
Is is a correct one?
DELIMITER $$
DROP FUNCTION IF EXISTS f_emp_info;
CREATE FUNCTION f_emp_info (f_first_name VARCHAR(255), f_last_name VARCHAR(255)) RETURNS DECIMAL(10,2)
DETERMINISTIC NO SQL READS SQL DATA
BEGIN
DECLARE f_latest_contract_salary DECIMAL(10,2);
SELECT
s.salary INTO f_latest_contract_salary
FROM
salaries s
WHERE
s.emp_no = (SELECT
e.emp_no
FROM
employees e
WHERE
e.last_name = f_last_name
AND e.first_name = f_first_name)
AND s.from_date IN (SELECT
MAX(s.from_date)
FROM
salaries s
JOIN
employees e ON e.emp_no = s.emp_no
WHERE
e.last_name = f_last_name
AND e.first_name = f_first_name);
RETURN f_latest_contract_salary;
END$$
DELIMITER ;
SELECT employees.f_emp_info('Aruna', 'Journel');
1 answers ( 0 marked as helpful)
Hi Eslam!
Thanks for reaching out.
Yes, your alternative solution is correct.
Hope this helps.
Best,
Tsvetelin