Subject OT: Re: Invalid SQL ?
Author Svein Erling Tysvær
Hi Christian!

I don't know what the SQL standard says, maybe your use of union (in
the where clause) is not allowed there.

Logically, you could write

select count(*) as N, ACHSSEGMENTID from DATA_FEA
where
not (ACHSSEGMENTID in
(select achssegmentid from achssegment) or
(ACHSSEGMENTID in
(select gebietid from gebiet))
group by ACHSSEGMENTID

However, I'd rather write (at least equally readable, and probably
considerably quicker)

select count(*) as N, ACHSSEGMENTID from DATA_FEA
where not exists(select * from achssegment
where achssegment.ACHSSEGMENTID = DATA_FEA.ACHSSEGMENTID)
and not exists(select * from gebiet
where gebiet.gebietid = DATA_FEA.ACHSSEGMENTID)

And Christian, please ask support questions at fb-support next time,
firebird-general is not for this kind of questions (though I think you
know already, since you've frequented the correct lists for several
years?).

Set

--- In Firebird-general@yahoogroups.com, "Christian Kaufmann" wrote:
> The following query works on my database:
>
> select achssegmentid from achssegment union select gebietid from
> gebiet
>
> But if I use it like this I receive an error
>
> select count(*) as N, ACHSSEGMENTID from DATA_FEA
> where
> not (ACHSSEGMENTID in
> (select achssegmentid from achssegment union select gebietid
from
> gebiet))
> group by ACHSSEGMENTID
>
>
> SQL error code = -104 Token unknown - line 4, char 44 union
>
> Do I need a view for the union ?
>
> cu Christian