[RESOLVED] help looping my select statment
hey all,
I have this...
Code:
select company,sum(minutes) from production_table as A
right join customers as C
on A.customerID=C.id
where C.id=1
That returns a single row where c.id=1. How do eliminate the c.id=1 and return a row for every customer?
I'm using mysql if it matters
thanks
kevin
Re: help looping my select statment
Am I missing something? Wouldn't you just remove the WHERE clause?
Re: help looping my select statment
Removing the where clause was one of the first things I tried. When I did I ended up with the value of company field from the first row of table C and the sum total of all rows in table A.
Re: help looping my select statment
Here is the sql for the table creation if it helps...
Table A:
Code:
CREATE TABLE `production_table` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`customerID` INT(11) NOT NULL,
`minutes` FLOAT NOT NULL,
PRIMARY KEY (`id`),
INDEX `FK_production_table_customers` (`customerID`),
CONSTRAINT `FK_production_table_customers` FOREIGN KEY (`customerID`) REFERENCES `customers` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=92
;
Table B:
Code:
CREATE TABLE `customers` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`company` VARCHAR(255) NOT NULL COLLATE 'latin1_general_ci',
PRIMARY KEY (`id`)
)
Re: help looping my select statment
Add the Group By
Code:
select company,sum(minutes) from production_table as A
right join customers as C
on A.customerID=C.id
Group by company
-tg
Re: help looping my select statment
Marvelous.
Thanks tg
kevin