DELIMITER // CREATE procedure min_frm_friends (IN sdate DATE, IN edate DATE) BEGIN IF char_length(sdate) < 1 THEN SET response := 20070101; end if; if char_length(edate) < 1 then set response := 20200101; end if; SELECT MAX(date),time,Personal.pc.firstname,Personal.pc.lastname,number,count(minutes) AS minutes FROM phonelog,Personal.pc WHERE phonelog.number IN(Personal.pc.businessphone,Personal.pc.mobilephone,Personal.pc.homephone) AND sdate < date and edate > date GROUP BY firstname ORDER BY minutes; END// DELIMITER ;