How do I create a function in mysql?
Notice the following uses a custom delimiter. This is to deal with the ambiguity of the semicolon delimiter that would otherwise be used to both delimit the function body and the function declaration.
DROP FUNCTION IF EXISTS getLastDate $$
CREATE FUNCTION getLastDate(eid int, tid int) RETURNS date
DECLARE d date;
select max(valid_date) into d from employees where employee_id = eid and _type = tid;