Subject | Re: [firebird-support] join and columns with the same name on diferent tables |
---|---|
Author | Alexandre Benson Smith |
Post date | 2004-04-06T20:53:53Z |
At 17:24 06/04/2004 -0300, you wrote:
I ALWAYS put alias on all my fields... This query was a test I was doing on
the weekend, and write it directly without the where clause, after this I
put the where to filter some records and FORGOT to put the alias...
When I see the strange result I look ate the where i saw no alias on the
fields.
Because I expect an server error if I don't put alias on ambiguous query I
post the message asking if the error should or shouldn't occur. I thought
it should.
The Original query was:
Select
NF.NotaFiscalID, NF.Numero, NF.Saida, NF.Cancelada,
NF.EmpresaRazaoSocial, NF.EmpresaCGC, NF.EmpresaInscricaoEstadual,
Es.UF as UF, NF.Emissao, NF.FretePorConta,
NFI.ICMSAliquota, NFI.IPIAliquota, NOP.CMP_CFOP,
EI.SituacaoTributaria, NFI.Item, P.Codigo as ProdutoCodigo,
UM.Sigla as UnidadeMedidaSigla, NFI.Quantidade,
NFI.Unitario, NFI.ICMSBaseValor, NFI.ProdutoClassificacaoFiscal
from
NotaFiscal NF join
NotaFiscalItem NFI on (NFI.NotaFiscalID = NF.NotaFiscalID) join
Produto P on (P.ProdutoID = NFI.ProdutoID) join
Unidade UM on (UM.UnidadeID = P.UnidadeID) join
NaturezaOperacao NOP on (NOP.NaturezaOperacaoID =
NFI.NaturezaOperacaoID) join
NotaFiscalEndereco NFE on (NFE.NotaFiscalID = NF.NotaFiscalID and
NFE.Tipo = '1') join
Estado Es on (Es.EstadoID = NFE.EstadoID) join
EstadoICMS EI on (EI.EstadoID = Es.EstadoID and
EI.ClassificacaoFiscalID = P.ClassificacaoFiscalID)
where
NF.Numero between 21497 and 21500 -- Here I forgot the alias
order by
NF.Emissao, NF.Numero, NFI.Item
I put a simple one just to show what I got...
I have a field Numero on Table NotaFiscal and on Table Endereco
Numero on NotaFiscal is "Invoice Number" (integer)
Numero on Endereco is "Address Number" (char, could be "kilometer 26" for
example)
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
----------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.631 / Virus Database: 404 - Release Date: 17/03/2004
[Non-text portions of this message have been removed]
>Hi,Hi Daniel,
>
>At April 6, 2004, 16:51, Alexandre Benson Smith wrote:
> > What I could not understand is, why the client tools (whatever they are)
> > don't report the error.... Since it's a server side error...
>
>I don't think that it is.
>
> > Thank you for the explanation that it's only reported on Dialect 3... I
> > don't remenber to read it...
>
>This was part of a discussion when FB 1.0 was still in beta, about 3
>years ago.
>
> > I thought ambiguous fields check will broke any old applications. And I was
> > wondering why don't break my bogus query... :)
>
>Although dialect 3 does the check, it is a very good practice to
>qualify your fields even in dialect 1. The reason why this check was
>put in place was that it was proven that the result can be erroneous
>and not consistent.
>
>Taking your first example, the field Number could be taken from either
>Table1 or Table2, and this can be random everytime you would prepare
>the query. Your example makes it obvious, because in Table1 Number is
>an Integer and in Table2 Number is a varchar. But, imagine if the
>field Number in both tables were integers, and that you would see
>different results with the same Where clause, from time to time, then
>you would be wondering what's wrong.
I ALWAYS put alias on all my fields... This query was a test I was doing on
the weekend, and write it directly without the where clause, after this I
put the where to filter some records and FORGOT to put the alias...
When I see the strange result I look ate the where i saw no alias on the
fields.
Because I expect an server error if I don't put alias on ambiguous query I
post the message asking if the error should or shouldn't occur. I thought
it should.
The Original query was:
Select
NF.NotaFiscalID, NF.Numero, NF.Saida, NF.Cancelada,
NF.EmpresaRazaoSocial, NF.EmpresaCGC, NF.EmpresaInscricaoEstadual,
Es.UF as UF, NF.Emissao, NF.FretePorConta,
NFI.ICMSAliquota, NFI.IPIAliquota, NOP.CMP_CFOP,
EI.SituacaoTributaria, NFI.Item, P.Codigo as ProdutoCodigo,
UM.Sigla as UnidadeMedidaSigla, NFI.Quantidade,
NFI.Unitario, NFI.ICMSBaseValor, NFI.ProdutoClassificacaoFiscal
from
NotaFiscal NF join
NotaFiscalItem NFI on (NFI.NotaFiscalID = NF.NotaFiscalID) join
Produto P on (P.ProdutoID = NFI.ProdutoID) join
Unidade UM on (UM.UnidadeID = P.UnidadeID) join
NaturezaOperacao NOP on (NOP.NaturezaOperacaoID =
NFI.NaturezaOperacaoID) join
NotaFiscalEndereco NFE on (NFE.NotaFiscalID = NF.NotaFiscalID and
NFE.Tipo = '1') join
Estado Es on (Es.EstadoID = NFE.EstadoID) join
EstadoICMS EI on (EI.EstadoID = Es.EstadoID and
EI.ClassificacaoFiscalID = P.ClassificacaoFiscalID)
where
NF.Numero between 21497 and 21500 -- Here I forgot the alias
order by
NF.Emissao, NF.Numero, NFI.Item
I put a simple one just to show what I got...
I have a field Numero on Table NotaFiscal and on Table Endereco
Numero on NotaFiscal is "Invoice Number" (integer)
Numero on Endereco is "Address Number" (char, could be "kilometer 26" for
example)
>--See you !
>Best regards,
> Daniel Rail
> Senior System Engineer
> ACCRA Group Inc. (www.accra.ca)
> ACCRA Med Software Inc. (www.filopto.com)
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
----------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.631 / Virus Database: 404 - Release Date: 17/03/2004
[Non-text portions of this message have been removed]