Subject RE: [ib-support] Offtopic basic SQL Question - Thanks
Author C Fraser
Thanks Dmitry,

That works heaps faster!!

Regards
Colin

-----Original Message-----
From: Dmitry Yemanov [mailto:dimitr_ex@...]
Sent: Thursday, 6 September 2001 8:16 p.m.
To: ib-support@yahoogroups.com
Subject: RE: [ib-support] Offtopic basic SQL Question


C Fraser,

> A simple question about SQL...
>
> Say you have a table of customers, invoices and invoice items, and you

> want to do a query on the customers returning their ID, first name,
> last name, phone, etc and a list of invoices and their totals
>
> [snip]

I'd suggest something like this:

select
C.Id,
C.FirstName,
C.LastName,
etc,...
I.Id,
I.Date,
( select sum(Quantity * Price) from Invoice_Item where Invoice_Id =
I.Id ) Sum_Of_Invoice from
Customer C join Invoice I on C.Id = I.Customer_Id
;

It may or may not be better depending on your tables structure, indices
and number of records.

HTH,
Dmitry


######################################################################
Attention:
The information in this email and in any attachments is confidential.
If you are not the intended recipient then please do not distribute,
copy or use this information. Please notify us immediately by return
email and then delete the message from your computer.
Any views or opinions presented are solely those of the author.
######################################################################