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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
kretzschmarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.