Subject Re: [ib-support] subquery problem
Author Helen Borrie
At 09:29 AM 19/03/2003 -0300, you wrote:
>hi !!
>
>I want to perform a subquery like the simple following one:
>
>
>select K.*
>from (select *
> from tablename
> where field1=val1) K
>
>It always raise an error at the select statement next to from.
>How can I do that ?


You're getting an error because your SQL syntax is wrong.

Here's a simple SQL select statement:

select field1,
field2,
field3
from aTable;

A subquery allows you to replace ONE output field with the output of
another select query. This output of the subquery must be SCALAR - meaning
it can be only one column wide and one row deep.

So here's the same query, with field3 replaced by a subquery:

select field1,
field2,
(select aField from tableB where id=99) AS sqField
from aTable;

If you need to use multiple columns tableB, you would need multiple
subqueries on tableB - which is V E R Y slow. Find a way to use a join
instead; or write a selectable stored procedure.

heLen