I have a SQL problem in my query, it follows:
$sql = "SELECT
cl.codigo,
pa.codigo AS codigo_participante,
pa.nome AS nome_participante,
cl.usuario,
cr.data AS data_geracao,
cl.validade,
cl.chave
FROM
participante pa,
conta_receber cr,
parcela_conta_receber pcr,
chave_liberacao cl
WHERE
pa.codigo = cr.codigo_participante
AND EXTRACT (YEAR FROM cl.validade) = '2017'
AND cr.numero = pcr.numero_conta_receber
--AND pcr.codigo_chave_liberacao = cl.codigo
--AND pa.codigo = 23
GROUP BY
cl.codigo,
pa.codigo,
pa.nome,
cl.usuario,
cr.data,
cl.validade,
cl.chave";
$resultado = $this->db->query($sql);
When I run this same query in the database, it returns me, but when it's in the code it's 0 the result, is there a problem in this query?
Explain better, this sql up there I load in the model to populate a list in the view. Since querry is very complex, I'm not using the querry builder in codeigniter , honestly, I would not even know how to use it in that querry. Anyway, when I use the $this->db->query($sql)
method, it returns an empty array, but that same sql, placed in my DBMS returns several tuples. I've come to see that there are other people with similar errors, when querry is too complex, codeigniter can not execute it correctly, returning an empty array. But, here comes the cat jump, when I remove two conditions from WHERE
, $this->db->query($sql)
returns me several values, the two lines are indicated as comments in the above code.