MySQL select...into variable yields null, even though data is there
For a while, this one eluded me. I don't like SELECT ... INTO, so I really wanted to blame it for your trouble, but no.  

Here'e the problem.

SELECT id
  INTO fqdn_id
  FROM UrlFqdn
 WHERE authority=authority_id AND name=fqdn;


How does MySQL interpret this?

SELECT id
  INTO fqdn_id
  FROM UrlFqdn
 WHERE 'mail4' = 1 AND name = 'mail4.z.uk';
/* Impossible WHERE */
/* see DECLARE authority TEXT; */



  &ldquo;A local variable should not have the same name as a table column.   If an SQL statement, such as a SELECT ... INTO statement, contains a reference to a column and a declared local variable with the same name, MySQL currently interprets the reference as the name of a variable.&rdquo;
  
  &mdash;&nbsp;http://dev.mysql.com/doc/refman/5.7/en/local-variable-scope.html


Using the same identifier for a variable and a column name makes a debugging mess, one way or another.