Last answered:

17 Feb 2023

Posted on:

16 Feb 2023

1

Why not do it in a shorter syntax such as listed below?

Here we do not have to create the max_date variable, but provides the same output? 


DROP FUNCTION IF EXISTS emp_info;
DELIMITER $$
USE employees$$
CREATE FUNCTION emp_info(f_first_name VARCHAR(25), l_last_name VARCHAR(25)) RETURNS DECIMAL(10,2) 
DETERMINISTIC
BEGIN
    DECLARE recent_salary DECIMAL(10,2);
    SELECT s.salary INTO recent_salary
    FROM employees e
    JOIN salaries s ON e.emp_no = s.emp_no 
    WHERE e.first_name = f_first_name AND e.last_name = l_last_name
    ORDER BY s.from_date DESC
    LIMIT 1;
    RETURN recent_salary;
END$$
DELIMITER ;

1 answers ( 0 marked as helpful)
Instructor
Posted on:

17 Feb 2023

0

Hi Nicholas!
Thanks for reaching out!

 

Some tasks may have more than one solution. So, your solution is correct.


Hope this helps.
Best,
Tsvetelin

Submit an answer