Subject | Help: unions within a subquery is it possible? |
---|---|
Author | bkehase2000 |
Post date | 2003-04-23T17:45:13Z |
I am trying the make the following work!
During a summarisation process, I am extracting sets of IDs from a
table, which I wish to use as an input to a further query. At the
moment, I am using the following technique - queries UNIONED
together, which I wish to use as a subquery. In my actual code, I
have a dynamic number of additional subsets I "union on".
The UNION statement below works fine by itself, producing a valid
list. However, the whole does not - FB gives the error at the bottom.
I am thinking along the following lines :-) :
1) My syntax may be wrong
2) Unions cannot be used within subqueries (?)
3) Perhaps there is a better way of doing this.
4) What is the maximum length of a SQL statement - at the moment I am
solving this by using two passes, where I generate a piece of SQL
with an IN construct - but this list of values could grow very large -
hence this overall problem.
I would greatly appreciate any help on this.
Regards
Berhane
select
x.*
from
element x
where
x.element_id in
(
select
b.element_id
from
entity a
inner join element b on (b.object_id = a.entity_id)
and(b.element_type_id =2)
where
(a.system_id = 1)
UNION
select
b.element_id
from
attribute a
inner join element b on (b.object_id =
a.attribute_id) and(b.element_type_id =3)
inner join entity c on (c.entity_id = a.entity_id)
where
(c.system_id = 1)
);
FB error:
ISC ERROR CODE:335544569
ISC ERROR MESSAGE:
Dynamic SQL Error
SQL error code = -104
Token unknown - line 15, char 2
UNION
During a summarisation process, I am extracting sets of IDs from a
table, which I wish to use as an input to a further query. At the
moment, I am using the following technique - queries UNIONED
together, which I wish to use as a subquery. In my actual code, I
have a dynamic number of additional subsets I "union on".
The UNION statement below works fine by itself, producing a valid
list. However, the whole does not - FB gives the error at the bottom.
I am thinking along the following lines :-) :
1) My syntax may be wrong
2) Unions cannot be used within subqueries (?)
3) Perhaps there is a better way of doing this.
4) What is the maximum length of a SQL statement - at the moment I am
solving this by using two passes, where I generate a piece of SQL
with an IN construct - but this list of values could grow very large -
hence this overall problem.
I would greatly appreciate any help on this.
Regards
Berhane
select
x.*
from
element x
where
x.element_id in
(
select
b.element_id
from
entity a
inner join element b on (b.object_id = a.entity_id)
and(b.element_type_id =2)
where
(a.system_id = 1)
UNION
select
b.element_id
from
attribute a
inner join element b on (b.object_id =
a.attribute_id) and(b.element_type_id =3)
inner join entity c on (c.entity_id = a.entity_id)
where
(c.system_id = 1)
);
FB error:
ISC ERROR CODE:335544569
ISC ERROR MESSAGE:
Dynamic SQL Error
SQL error code = -104
Token unknown - line 15, char 2
UNION