Subject Offtopic basic SQL Question
Author 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

To get the total for each invoice involves doing a sum and grouping by
the invoice, but, for the query to work, you have to group by all the
other customer fields... Is this the best way to do it, or does it slow
things down heaps... is some type of sub query thing better???

Eg. I have something like:

Select
Customer.Id,
Customer.FirstName,
Customer.LastName,
etc, ...
Invoice.Id,
Invoice.Date,
SUM( Invoice_Item.Quantity * Invoice_Item.Price) Sum_Of_Invoice
FROM Customer
INNER JOIN Invoice ON (Customer.Id = Invoice.Customer_Id)
INNER JOIN Invoice_Item ON (Invoice.Id = Invoice_Item.Invoice_Id)
GROUP BY
Invoice.Id,
Invoice.Date,
Customer.Id,
Customer.FirstName,
Customer.LastName,
etc,

Thanks for any advice

C Fraser


######################################################################
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.
######################################################################