MySQL Surnames in Inner Join

9

I tried to do this internal join in SQL to link two tables in my report.

What I would be doing wrong, why is giving "Unknown ffccf column", even though I am naming the column?

Follow the code:

SELECT finafim.ccf as ffccf, finafim.impcaixa, finafim.numcup, finafim.vlfina, finafim.descfina,
       tabc470.ccf as t4ccf, tabc470.NSerie, tabc470.numcupom
FROM finafim
INNER JOIN tabc470
ON (finafim.numcup = tabc470.numcupom)
AND (finafim.ccf = tabc470.ccf)
AND (finafim.impcaixa = tabc470.NSerie)
WHERE ffccf= :ppccf AND numcup= :ppcoo AND impcaixa= :ppecf //Detalhes de parâmetros para igualar valores.
AND dtcomp BETWEEN "2014/03/01" AND "2014/05/01"
    
asked by anonymous 29.05.2014 / 15:03

2 answers

1
SELECT DISTINCT ff.ccf AS ffccf, ff.numcup, ff.impcaixa, t46.ccf AS t46ccf, t46.numcupom, t46.NSerie 
FROM finafim AS ff INNER JOIN tabc470 AS t46 
ON (ff.numcup = t46.numcupom) AND (ff.ccf = t46.ccf) AND (ff.impcaixa = t46.NSerie)
WHERE ff.ccf= :ppccf AND numcup= :ppcoo AND impcaixa= :ppecf //Detalhes de parâmetros para igualar valores. 
AND dtcomp BETWEEN "2014/03/01" AND "2014/05/01"

Follow the correct code ... It just points to the column exactly as the Omni said in those 3 conditions. I was pointing it inside the Where, where it is not feasible, nor even allowed.

Sorry for the lack of organization, it is that my company has blocked several forums, and I am not able to organize my right post.

    
30.05.2014 / 16:11
9

You can only use referencing columns by their apelidos ( alias ) in the following clauses:

  • GROUP BY
  • ORDER BY
  • HAVING

( MySQL Documentation )

So in your case your query would have to reference the columns directly in WHERE instead of using apelidos .

    
29.05.2014 / 15:10