Subject Re: [IBO] error in sql when I put distinct keyword
Author Ronaldo Rezende Vilela Luiz
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?

> SELECT i1. INSTITUICAO,
> i1.NOME AS NOME_INSTITUICAO <== why do you need to alias this? // ok this
is not necessary.
> FROM INSTITUICAO i1
> 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.

Where I used the SQL-89 JOIN? What Join I must use with IBO?

> Also, I recommend omitting the PLAN clause...until you understand SQL
> 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.
I don't use the PLAN. I only was copy and paste the text gennerated by the
plan to show to the members of the list.
>
> >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
table,
> >the field that I want to be distinct is a primary key. And in the table
> >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.
ok, sorry.
> regards,
> Helen Borrie (TeamIBO Support)