I currently have the following:
Table:
Table Provider:
The following query returns the number of suppliers for each city:
SELECT t.id, t.name, count(s.id) as NumSupplier
FROM Town t
INNER JOIN Suppliers s ON s.town_id = t.id
GROUP BY t.id, t.name
Now I want to present another table in a query, Supplier_vehicles. A supplier can have many vehicles:
Provider_vehicles table:
Now, the NumSupplier field should indicate the number of suppliers for each city that have any of the car_id data (state IN):
The following query will simply return vendors that have any of the vehicle_id data:
SELECT * FROM Supplier s, Supplier_vehicles v WHERE s.id = v.supplier_id AND v.vehicle_id IN (1, 4, 6)
I need to integrate this into the first request so that it returns the number of providers that have any of the vehicle_id data.