I have two tables: Products and Suppliers. SupplierID is a foreign key in products table. I need to make a table that contains country, supplierID, company name all from the supplier table then I need to have the number of products each supplier has. I tried the following query:
SELECT DISTINCT s.country,
s.supplierid,
s.companyname,
(SELECT Count(DISTINCT productid) AS
"Number of Products Supplied"
FROM products
INNER JOIN suppliers
ON p.supplierid = s.supplierid) AS
"Number of products Supplied"
FROM suppliers s,
products p
WHERE ( s.country = 'usa'
OR s.country = 'uk' )
AND s.supplierid = p.supplierid
But I get the total number of products and not number of products supplied by each supplier. Any ideas?