Subject Re: [firebird-support] unions in sub-selects
Author Helen Borrie
At 04:00 AM 9/02/2005 +0000, you wrote:


>FB balks at doing a union in a subquery, e.g.:
>
>select * from Table1
>where Table1_ID in (Select Table1_ID from Table2 union Select
>Table1_ID from Table3)

Yes, of course, because a union implies multiple rows and a subquery MUST
return 0 or 1 row.

>Is the only way to achieve that via a stored procedure?

Probably, but it's not necessary. You can just replace your query with this:

select t1.* from Table1 t1
where EXISTS (
select 1 from Table2 t2
where t2.Table1_ID = t1.Table1_ID)
OR EXISTS (
select 1 from Table3 t3
where t3.Table1_ID = t1.Table1_ID)

./hb