This is the data structure:
stores { id, name, city_id, owner_id }
cities { id, name }
store_managers { user_id, store_id }
products { id, name, store_id }
users { id, name }
_______________________________________
#note: many users can manage the same store, and the same user can manage
many stores.
I need to get, in one query:
- The stores that owned by the user that its id I will provide. [from stores, when owner_id = some_number]
- For each store, the city that is attached too. [from cities]
- The users that have manage privileges to the store. [from store_managers]
- the COUNT of products that is assigned to each store.
I need it to be in one query. The DB is MYSQL
fixed, added the missing foreign key my mistake, thanks