Jump to content

Help with PHP Code Left Join


vican

Recommended Posts

Fairly new to PHP/Mysql, help please...

 

Say I have 2 tables

Table A: Customer

ID  |  Name

 

1    |  Adam

 

2    |  Bravo

 

3    |  Charlie

 

4    |  Dennis

 

Table B: Sales

ID    Year      Amount

 

1      2007        10

 

1      2007          20

 

1      2008          30

 

2      2008          40

 

2      2008          50

 

2      2008        60

 

3      2007        70

 

3      2007          80

 

4      2008          100

 

 

and I need to list all customers and their sales amount in 2008(even if they don't have any sales in 2008). I had the following code which only returns 2008 results.

 

Select Customer.ID, Customer.Name, sum(Sales.Amount )

from Customer

Left join Sales on customer.id= sales.id

Where sales.year = 2008

group by customer.name

 

I am stuck. Any help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/101125-help-with-php-code-left-join/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.