Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread querying a result set
Wed, Sep 16 2009 12:51 PMPermanent Link

Van de moortel, Koen
I have a query like this:
query1.sql.text:='select .... from ....');

and now I want to make a subquery from query1, something like:
query2.sql.text:='select .... from query1';

But this doesn't work.  Does the result set from query1 have a name that I can use in query2?  Or is there another way to make this work?

(I could just put the whole "select..." from query1 in the sql statement of query2, but query1 is slow, so I want to avoid that.)

Thanks for any help!
Wed, Sep 16 2009 3:09 PMPermanent Link

Uli Becker
Van de moortel,

> But this doesn't work.  Does the result set from query1 have a name that I can use in query2?  
Or is there another way to make this work?

You can create a Memory table from query1 and query this table. Create a
Database in Memory "MyMemoryDB".
Using MyMemoryDB as the current database for the TEDBQuery, execute this
SQL:

CREATE TABLE MyTable AS SELECT * FROM MyDB.MyTable;

Uli
Wed, Sep 16 2009 3:49 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Van,

<< But this doesn't work.  Does the result set from query1 have a name that
I can use in query2?  Or is there another way to make this work? >>

There are several ways to solve this.  You could:

1) Create a view for query1, and then refer to the view name in query 2.
2) Use a derived table for query1, which is equivalent to creating a
temporary view for query1 while query2 is prepared.
3) Use CREATE TEMPORARY TABLE..AS to create a named temporary table that
contains the result set for query1.

It really depends upon whether you want query1 to "hang around" for a while
and be available for more than just query2.  If that is the case, then 1)
and 3) are your best options.  If you only want query1 to be available for
query2, then 2) is your best option.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image