No soy un experto en bases de datos de ninguna manera, pero así es como lo hago.
http://www.somethinghitme. com/2010/05/06/mysql-almacenado-procedimientos-si-no-existe/
DECLARE SomeId int;
DECLARE CheckExists int;
SET CheckExists = 0;
SELECT 1 INTO CheckExists from lookup_table WHERE someField = in_SomeParam LIMIT 1;
IF (CheckExists > 0) THEN
SELECT id INTO SomeId FROM lookup_table WHERE someField = in_SomeParam;
ELSE
INSERT INTO lookup_table (someField ) VALUES(in_SomeParam);
SELECT SomeId = LAST_INSERT_ID();
END IF;