0

I have 2 tables in my database and I am trying to get data from both of the tables.

The first table contains the customer data. The second table contains the of the customer. I am using INNER JOIN to select the customer data and some financial data of the customer.

Here is the SQL statement I am using:

SELECT cus.id, cus.name, cus.address, count(invoices.id) as id2, CONCAT('€ ', ROUND(SUM(invoices.total),2)) as total
FROM cus
INNER JOIN invoices
ON cus.cus_id = invoices.cus_id 

This script works when the customer has invoices in the database. But if the customer has no invoices the statement responses NULL for all the columns.

If there is no data in count(invoices.id) as id2 and CONCAT('€ ', ROUND(SUM(invoices.total),2)) as total I still want to show the data for the customer. But currently I am getting NULL.

Does someone know what is wrong with my statement and how I can fix this problem?

John
  • 904
  • 8
  • 22
  • 56
  • LEFT OUTER JOIN worked in my case. Thanks – John Jun 11 '17 at 00:11
  • "But if the customer has no invoices the statement responses NULL for all the columns." What do you mean? INNER JOIN doesn't do that. Do you mean that's what you want? PS Please read [mcve]. – philipxy Jun 11 '17 at 01:01

0 Answers0