Reputation: 1
Trying to find how many active or inactive rentals there are for a specific store. 1 = active, 0 = inactive. the answer I get doubles the amount of customers and is not right. Can anyone help
SELECT COUNT(*)
FROM customer, store
WHERE active = 0
AND store_id = 2
ORDER BY customer_id;
Upvotes: 0
Views: 626
Reputation: 209
The join is incorrect. There are no join criteria specified so the result is all possible combinations of customers and stores, filtered by where
clause.
Correct way to join is:
...
from customer inner join store on store.store_id = customer.store_id
...
(assuming customer
table has the store_id
field).
And you probably want to group by store using the group by
clause.
Upvotes: 1