I have 3 tables:
- Users (id, name)
- Orders (id, userId)
- Orders_Items (id, orderId, status)
At first I wanted to list all users with their respective count of orders like this:
- A, 1 order
- B, 5 orders
That's easy, I'm doing a "select name, count(id) from users, orders where users.id = orders.userId group by name".
Now, I'd like to further filter this data to show only users with orders that have items with status = "unprocessed". I am not sure how to go about grouping data from 2 tables. In the end, I'm looking to get data like:
- (A not shown, no order with any item having status = unprocessed)
- B, 3 orders (2 orders have no item with status = unprocessed).
Thanks!