TQuery Sub Queries

I am using the TQuery component to retrieve data from my tables, but I now need to run sub queries on the retrieved data. How can I do this
Leon_bAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kretzschmarConnect With a Mentor Commented:
well ok,

here it goes

//save the result as Table
procedure TForm1.Button1Click(Sender: TObject);
Var T : TTable;
begin
  query1.Open;
  T := TTable.Create(self);
  try
    T.DatabaseName := query1.DatabaseName;
    T.TableName := 'ResultOfQuery1';  //or whatevername
    T.BatchMove(query1,BatCopy);
  finally
    T.Free;
  end;
  query1.Close;
end;

now you can go ahead and
query this temporary table

meikl
0
 
kretzschmarCommented:
hi leon_b,

simple method:
just use a filter
(its also available for querys)

complex method:
create a table of the resultset and query then the new table

let me know which way you want to go,
to give you additional advice for this
(if needed).

meikl



0
 
Leon_bAuthor Commented:
I am already using a filter and I need to use aggregate functions so I think I will go with the latter.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ITugayCommented:
Hi Leon_b!

Did you try

select FIELD_A1,FIELD_A2 from TABLE_A
where FIELD_A0 in (select FIELD_B0 from TABLE_B where condition)

Best regards.
Igor.
0
 
kretzschmarCommented:
hi ITugay,

subselects are not possible in all databases,
but maybe, it is possible by the database which leon is using.

meikl
0
 
ITugayCommented:
To  kretzschmar.

I hope the Interbase there:)
0
 
Leon_bAuthor Commented:
Thanks for the idea, but I've tried it before and there are to many columns that need to be selected without a SELECT * and most of the code has already been written.  Changing that now will set me back at least a day or 2.  Plus the fact that the code for the first query is dynamicly created at runtime.
0
All Courses

From novice to tech pro — start learning today.