SELECT Customers.Account, Customers.Deptname, Renewal.Id, Customers.ID, Renewal.Startdate, Renewal.enddate, Renewal.Status, Renewal.PrintedOn, COUNT(InvoiceLineItems.invID) FROM Customers INNER JOIN Renewal ON Customers.Account = Renewal.Account INNER JOIN InvoiceLineItems ON Renewal.Id = InvoiceLineItems.invID WHERE ((Customers.company)='Foo Bar') ORDER BY Customers.Account;
The above Is my problem query which gets data from three tables, it gives the error "Column 'Customers.Account' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause." This WAS working previously when it was linking only two tables and not getting the count from the InvoiceLineItems table, working query seen below. The change was to determine how many rows are in a third table, InvoiceLineItems, with an invID and Account that match Reneals Id and Account. I'll add some example data at the bottom of the post.
SELECT Customers.Account, Customers.Deptname, Renewal.Id, Customers.ID, Renewal.Startdate, Renewal.enddate, Renewal.Status, Renewal.PrintedOn FROM Customers INNER JOIN Renewal ON Customers.Account = Renewal.Account WHERE ((Customers.company)='Foo Bar') ORDER BY Customers.Account;
I'm not all that proficient with SQL and the things I've tried after searching the issue either don't seem to apply or after applying produce their own new errors
Example Data with Proposed column being the count
Each Account has a unique invoice number counting up from one, but each invoice may have multiple line items on it. Let me know if I've provided enough information, and thanks in advance!