Hi ppl,
Sorry for the vague subject, i dont know how to do a title for this one!!
Im using access to create SQL queries for a MySQL database.
I know i havent got this is in the MySQL section, but i think it is relevant as a general "query" question!
Anyway i have this query:
Code:
"SELECT customers.FirstName, scripts.ClaimID, customers.CustomerID,customers.ZCSignup,customers.ClaimPaperwork, customers.LastName, IFNULL(sum(scripts.PharmAmount),0) AS SumOfInvAmount FROM (customers INNER JOIN claims ON customers.CustomerID = claims.customerID) INNER JOIN scripts ON claims.ClaimID = scripts.ClaimID WHERE scripts.ReconcilID IS NULL AND scripts.ChemistID='".$_SESSION['chsh']."' GROUP BY customers.FirstName, customers.LastName ORDER BY customers.LastName ASC"
The idea is to generate a list of Customers, whose [SCRIPTS] are not reconciled. Thus WHERE scripts.reconcilID IS NULL.
I want this to display customer.lastname, customer.firstname and SUM(scripts.pharmamount) but if they have NO SCRIPTS that fit this WHERE clause, then the customer is still there but the sum =$0.00!!!
I have read some things about doing a SELECT within a SELECT and using IFNULL etc etc but it is beyond me and no matter how many i read, i cant get the syntax right!!!
Can anyone help or point me in the right direction??
Gangel