Subject | Re: [IBO] error in sql when I put distinct keyword |
---|---|
Author | Helen Borrie (TeamIBO) |
Post date | 2002-04-12T02:41:52Z |
At 07:36 PM 11-04-02 -0300, you wrote:
error is this query. Try the following:
SELECT i1. INSTITUICAO,
i1.NOME AS NOME_INSTITUICAO <== why do you need to alias this?
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.
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.
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)
** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com
>Look for my query:The error is generated by Firebird, on the first of several bad syntax
>SELECT INSTITUICAO
> , (SELECT NOME
> FROM INSTITUICAO
> WHERE INSTITUICAO.ID = CONTAS.INSTITUICAO) <== this makes no
> sense and is the source of the error being reported by Firebird
> AS NOME_INSTITUICAO
>FROM CONTAS C, TIPO_CONTA_CREDITO T
>WHERE C.TIPO=T.TIPO_CONTA AND TIPO_LANCAMENTO=:TIPO_LANCAMENTO
>----------
>PLAN (INSTITUICAO INDEX (RDB$PRIMARY9))
>PLAN JOIN (T INDEX (RDB$FOREIGN54),C INDEX (RDB$19))
>---------
>There is more then one register that have the same value of field
>INSTITUICAO in my result of query. When I try to put the DISTINCT (SELECT
>DISTINCT INSTITUICAO), I receive this error: ISC ERROR CODE: 335544343 ISC
>ERROR MESSAGE: invalid request BLR at offset 122 context alredy in use (BLR
>error).
>This error generated by Firebird or by ibo?
error is this query. Try the following:
SELECT i1. INSTITUICAO,
i1.NOME AS NOME_INSTITUICAO <== why do you need to alias this?
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.
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.
>Is there any problem if a do this query in 3 tables. If there isn't anyI think you are confused about DISTINCT. Please get hold of the Language
>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.
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)
** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com