title: MySQL Error 1172 - Result consisted of more than one row
body: <p>I'm getting this error from MySQL when running a query inside a stored procedure:</p>
  
  <blockquote>
    <p>Error Code: 1172
    Result consisted of more than one row</p>
  </blockquote>
  
  <p>I understand the error: I'm doing a <code>SELECT (...) INTO (var list)</code>, and thus the query is required to return a single row. When I use <code>LIMIT 1</code> or <code>SELECT DISTINCT</code>, the error goes away.</p>
  
  <p>However: when I run the original query manually (without <code>LIMIT</code> or <code>DISTINCT</code>), <strong>it does return a single row</strong>. So I'm suspecting I may have bumped into a MySQL bug. Does anyone know what could be happening?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I'm posting the SQL as requested. Everything that starts with an underscore is a variable declared earlier inside the procedure. When I test it, I'm replacing <code>_cd_pai_vc</code> with the ID for the record that is causing the problem.</p>
  
  <pre><code>SELECT  a.valor,    IFNULL(p.valor, 0), fn_cd2alias(ra.cd_registro),    fn_cd2alias(IFNULL(p.valor,0))
  INTO    _valor,     _cd_pai_vc,         _alias_verbete,                 _alias_pai
  FROM dados_registros ra
      INNER JOIN dados_varchar255 a
      ON a.cd_registro = ra.cd_registro
          AND a.fl_excluido = 0
          AND a.alias = 'vc-verbetes-termo'
      LEFT OUTER JOIN dados_registros rp
          INNER JOIN dados_int p
          ON p.cd_registro = rp.cd_registro
              AND p.fl_excluido = 0
              AND p.alias = 'vc-remissoes-termo referenciado'
          INNER JOIN dados_int pt
          ON pt.cd_registro = rp.cd_registro
              AND pt.fl_excluido = 0
              AND pt.alias = 'vc-remissoes-tipo remissao'
              AND fn_cd2alias(pt.valor) = 'hierarquica'
      ON ra.cd_registro = rp.cd_entidade
          AND rp.fl_excluido = 0
          AND fn_cd2alias(rp.cd_modulo) = 'vc-remissoes'
  WHERE ra.cd_registro = _cd_pai_vc 
      AND ra.fl_excluido = 0;
  </code></pre>