I have 2 tables created with SQL. The first one has an unique id and a name of a provider. The second one has a product name, the amount of that product and the id of the provider.
I need a query that gives me the name of each provider and the total sum of the product amount that they have.
Ex:
CREATE TABLE IF NOT EXISTS provider
(id int unique auto_increment primary key,
name char(50));
CREATE TABLE IF NOT EXISTS product
(id int unique auto_increment primary key,
name char(30),
provider_id int NOT NULL,
amount int NOT NULL);
Provider: (id, name)
1 Mike
2 Peter
3 John
Product: (id, name, provider_id, amount)
1 RedCar 1 100
2 BlueCar 1 50
3 RedCar 3 35
4 OrangeCar 2 500
5 GreenCar 3 250
Query:
Mike 150
Peter 500
John 285