Subject Re: [ib-support] Using LIKE with a subquery
Author Arno Brinkman
Hi,

> I have a query with a subquery. I would like the query to be able to use
the
> results from the subquery as part of what I am looking for.
>
> e.g. at the moment in the query's WHERE clause I have:
>
> WHERE THE_FIELD IN
> (select THE_FIELD
> from TABLE
> where 'a condition is satisfied')
>
> However, if one of the subquery results for the field in question was
> 'TEST', and in the main query I want to use this word and search for
> 'TEST%', is this possible.
>
> Instead of the word IN what I need is SQL that lets me say LIKE WHAT IS IN
> this subquery.
>
> Is this possible? Is there another way?

Maybe a JOIN could help in here, but a stored procedure is also a way to do
it.
Use the subselect as master select and use the other tables as join syntax :

SELECT
t2.*
FROM
TableSubSelect ts
JOIN Table t2 ON (t2.THE_FIELD LIKE ts.THE_FIELD || '%')
WHERE
ts.AField = 'a condition is satisfied'

Regards,
Arno