Query from Query 
Author Message
 Query from Query

I have big enough query with UNIONs and agregatives.
And then I need to build query that use result of first one.
But I can't use VIEW because UNIONs are illegal in VIEWs.
I can't build one big query because UNIONs haven't
a name and impossible to apply to fields names for joins.

In Access it is possible create first
query and save it like QUERY1 and then
write next query (simplified example):

SELECT Q1.f1, T1.* FROM QUERY1 Q1, Table1 T1
WHERE Q1.id = T1.id

(But delphi don't allow to query from query ;-( )

In DB2 it is possible to write:

SELECT Q1.f1, T1.* FROM (SELECT ...) Q1, Table1 T1
WHERE Q1.id = T1.id

(But IB don't allow to query from query ;-( )

Who know how to query from query on Delphi and
Interbase ?



Wed, 18 Jun 1902 08:00:00 GMT  
 Query from Query
If the query resultset is not huge, you can use a Tbatchmove and copy
the result to a local Ttable. Then execute the next query from that
table. Example:

with aBatchMove do
begin
 source :=yourQuery;
 destination :=aLocalTable;
 mode :=batCopy;
 execute;
end;

Remember to set

yourQuery.dataBaseName :=aLocalTable.databasename;

then

SELECT * FROM aLocalTable.tableName

Regards
Atle Markeng

Quote:

> I have big enough query with UNIONs and agregatives.
> And then I need to build query that use result of first one.
> But I can't use VIEW because UNIONs are illegal in VIEWs.
> I can't build one big query because UNIONs haven't
> a name and impossible to apply to fields names for joins.

> In Access it is possible create first
> query and save it like QUERY1 and then
> write next query (simplified example):

> SELECT Q1.f1, T1.* FROM QUERY1 Q1, Table1 T1
> WHERE Q1.id = T1.id

> (But Delphi don't allow to query from query ;-( )

> In DB2 it is possible to write:

> SELECT Q1.f1, T1.* FROM (SELECT ...) Q1, Table1 T1
> WHERE Q1.id = T1.id

> (But IB don't allow to query from query ;-( )

> Who know how to query from query on Delphi and
> Interbase ?



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Querying a query?

2. query on query

3. URG: re-query a query

4. Query Component query?

5. Local sql, query on query problem

6. Query on Queries

7. Querying a Query without writing to disk

8. Query on queries

9. Querying a Query

10. SELECT ... INTO tablename ... (was : re-query a query)

11. Join Query Record in the same Query...

12. Copying a query to another query

 

 
Powered by phpBB® Forum Software