Subject | Re: [IBO] error in sql when I put distinct keyword |
---|---|
Author | Ronaldo Rezende Vilela Luiz |
Post date | 2002-04-12T03:31:20Z |
I achieved what I wanted with this query:
SELECT DISTINCT
I.ID
, I.NOME
FROM INSTITUICAO I, CONTAS C, TIPO_CONTA_CREDITO T
WHERE T.TIPO_LANCAMENTO=:TIPO_LANCAMENTO AND
C.TIPO=T.TIPO_CONTA AND
I.ID=C.INSTITUICAO
What command I must use? This select or the select that you write for me
below? Anyone of this is better or worse?
plan to show to the members of the list.
SELECT DISTINCT
I.ID
, I.NOME
FROM INSTITUICAO I, CONTAS C, TIPO_CONTA_CREDITO T
WHERE T.TIPO_LANCAMENTO=:TIPO_LANCAMENTO AND
C.TIPO=T.TIPO_CONTA AND
I.ID=C.INSTITUICAO
What command I must use? This select or the select that you write for me
below? Anyone of this is better or worse?
> SELECT i1. INSTITUICAO,is not necessary.
> i1.NOME AS NOME_INSTITUICAO <== why do you need to alias this? // ok this
> FROM INSTITUICAO i1Where I used the SQL-89 JOIN? What Join I must use with IBO?
> JON CONTAS C ON i1.ID = C.INSTITUICAO
> JOIN TIPO_CONTA_CREDITO T ON C.TIPO=T.TIPO_CONTA
> WHERE T.TIPO_LANCAMENTO=:TIPO_LANCAMENTO
>
> Even when you understand the syntax, you should avoid the SQL-89 JOIN
> syntax with IBO so that you do not need to be concerned about JoinLinks.
> Also, I recommend omitting the PLAN clause...until you understand SQLI don't use the PLAN. I only was copy and paste the text gennerated by the
> better, the optimizer will do a much better job than you can, provided you
> have useful indexes. If you don't have useful indexes, then even your own
> "guesswork" plans will make the query perform badly.
plan to show to the members of the list.
>table,
> >Is there any problem if a do this query in 3 tables. If there isn't any
> >disadvantage I make this select in table instituicao, because in this
> >the field that I want to be distinct is a primary key. And in the tableok, sorry.
> >CONTAS, this field is a foreing key.
>
> I think you are confused about DISTINCT. Please get hold of the Language
> Reference or any good SQL reference and study how DISTINCT works. It may
> or may not be what you need here...
> In future, please post SQL problems to the ib-support list.
> regards,
> Helen Borrie (TeamIBO Support)