Board index » delphi » Has anyone done a TQuery within a TQuery?

Has anyone done a TQuery within a TQuery?

Hi all,
Got a question: Has anyone out there developed or worked on a TQuery
which could do a 'SELECT' within another 'SELECT'? In otherwords, a
kind of master-detail relationship which would enable you to see not
just the results from the "detail" but also those of the "master".

Any help would be much appreciated.

Hossein.

 

Re:Has anyone done a TQuery within a TQuery?


In article <01bbcc81$39683a00$0822a...@h.jelveh>, s...@vworlds.it says...

Quote

>Hi all,
>Got a question: Has anyone out there developed or worked on a TQuery
>which could do a 'SELECT' within another 'SELECT'? In otherwords, a
>kind of master-detail relationship which would enable you to see not
>just the results from the "detail" but also those of the "master".

>Any help would be much appreciated.

>Hossein.

A query on a query is impossible but you can try the following: if you have a
table customer with the number as a primary key and a table customerbills which
references customer (number) in the field customernumber with a foreign key you
can do the following select to get all customers and there related bills:

select * from customer, customerbills where
customer.number=customerbills.customernumber;

This works on all SQL-Servers but I don't know if it works on Local-SQL on
DBase- and Paradox-Tables.

Stefan

Re:Has anyone done a TQuery within a TQuery?


In article <01bbcc81$39683a00$0822a...@h.jelveh>, s...@vworlds.it says...

Quote

>Hi all,
>Got a question: Has anyone out there developed or worked on a TQuery
>which could do a 'SELECT' within another 'SELECT'? In otherwords, a
>kind of master-detail relationship which would enable you to see not
>just the results from the "detail" but also those of the "master".

Sounds like you are wanting to do a nested select?

Something like:

SELECT *
FROM table1
WHERE table1.OrderNumber IN
  (SELECT table2.Ordernumber
   FROM table2
   WHERE table2.field1 = 'some_value')

Is this what you are looking for?

CatYak

Re:Has anyone done a TQuery within a TQuery?


Quote
In article <01bbcc81$39683a00$0822a...@h.jelveh>, "Hossein Jelveh" <s...@vworlds.it> wrote:
>Hi all,
>Got a question: Has anyone out there developed or worked on a TQuery
>which could do a 'SELECT' within another 'SELECT'? In otherwords, a
>kind of master-detail relationship which would enable you to see not
>just the results from the "detail" but also those of the "master".

I'm not quite sure what you want.

Something like:

Select * from invoice inv where inv.cust_num in
(  Select * from Customer cust where cust.income > 50000)

Thisone returns all the invoices of customers with an income > 50000

R.E. den Braasem (aka The Graphical Gnome)
(r...@ktibv.nl)

Senior Software Engineer

Re:Has anyone done a TQuery within a TQuery?


On the blessed day Fri, 8 Nov 1996 08:30:27 GMT, A.D., the highly respected
r...@ktibv.nl (The Graphical Gnome) decided to pour from his infinite sources,
20 lines of wisdom upon the world, as follows:

Quote
>In article <01bbcc81$39683a00$0822a...@h.jelveh>, "Hossein Jelveh" <s...@vworlds.it> wrote:
>>Hi all,
>>Got a question: Has anyone out there developed or worked on a TQuery
>>which could do a 'SELECT' within another 'SELECT'? In otherwords, a
>>kind of master-detail relationship which would enable you to see not
>>just the results from the "detail" but also those of the "master".
>I'm not quite sure what you want.
>Something like:
>Select * from invoice inv where inv.cust_num in
>(  Select * from Customer cust where cust.income > 50000)
>Thisone returns all the invoices of customers with an income > 50000

Can such stuff be done in local SQL (with Paradox tables)?
Where can one read to learn what is possible with local SQL?
Svein Olav Mytting, Rosendalsv 7A, 0166 Oslo Norway. E-mail bolle...@telepost.no

Re:Has anyone done a TQuery within a TQuery?


Quote
In article <560frg$...@o.online.no>, bolle...@telepost.no wrote:
>>>Hi all,
>>>Got a question: Has anyone out there developed or worked on a TQuery
>>>which could do a 'SELECT' within another 'SELECT'? In otherwords, a
>>>kind of master-detail relationship which would enable you to see not
>>>just the results from the "detail" but also those of the "master".
>>I'm not quite sure what you want.

>>Something like:

>>Select * from invoice inv where inv.cust_num in
>>(  Select * from Customer cust where cust.income > 50000)

>>Thisone returns all the invoices of customers with an income > 50000

>Can such stuff be done in local SQL (with Paradox tables)?
>Where can one read to learn what is possible with local SQL?
>Svein Olav Mytting, Rosendalsv 7A, 0166 Oslo Norway. E-mail
> bolle...@telepost.no

I remember reading in the D1 online help that nested select statements cannot
be done with local SQL; I assume the same applies to D2

Pete

Re:Has anyone done a TQuery within a TQuery?


Quote

>I remember reading in the D1 online help that nested select statements cannot
>be done with local SQL; I assume the same applies to D2

>Pete

When you say Local SQL...are you referring to local Interbase tables or Paradox
tables.  I will have to look, but, I think Interbase, being a relational DB,
should handle nested selects where Paradox, file based DB, may not.  

CatYak

Other Threads