Subject Re: SQL question
Author dianeb77x
--- In ib-support@y..., "Burak OZLER" <burak.ozler@u...> wrote:
> Hi All..
>
> I'm using double fielded indexes at my database becouse of
replication purposes. At the sql statement below I'm trying to
retreive the CARI_GRUP_ID,CARI_GRUP_SID, CGKOD, CGADI
> from CARI_GRUP where the given CARI_ID and CARI_SID doesn't belong
to the CARI_GRUP_UYE
> -----------------------------
> CARI_GRUP TABLE
> -------------------------------
> * CARI_GRUP_ID
> * CARI_GRUP_SID
> CGKOD
> CGADI
> CGACK
> TIP
> --------------------------------------
> CARI_GRUP_UYE TABLE
> -------------------------------------
> *CARI_GRUP_ID
> *CARI_GRUP_SID
> *CARIID
> *CARI_SID
> VARSAY
> --------------------------
> * - Primary key fields
>
> Select CARI_GRUP_ID,CARI_GRUP_SID, CGKOD, CGADI
> From CARI_GRUP
> Where CARI_GRUP_ID Not In(Select CARI_GRUP_ID
> From CARI_GRUP_UYE
> Where CARIID=:PRM_CARI_ID And
CARI_SID=:PRM_CARI_SID)
> and CARI_GRUP_SID Not In(Select CARI_GRUP_SID
> From CARI_GRUP_UYE
> Where CARIID=:PRM_CARI_ID And
CARI_SID=:PRM_CARI_SID)
>
> The statement above must work right, but I feel that there must be a
better and more reliable way to do it.
>
> Any ideas?

What about using "where not exists" instead of "where ... not in"?

> Select CARI_GRUP_ID,CARI_GRUP_SID, CGKOD, CGADI
> From CARI_GRUP
> Where not exists
(Select *
From CARI_GRUP_UYE
where CARI_GRUP_UYE.CARI_GRUP_ID = CARI_GRUP.CARI_GRUP_ID And
CARI_GRUP_UYE.CARI_GRUP_SID = CARI_GRUP.CARI_GRUP_SID And
CARIID = :PRM_CARI_ID And
CARI_SID = :PRM_CARI_SID)

Or something like that.

Regards,
db