1
Part of my database consists of these three tables. And I’m trying to come up with an SQL query that tells me the clients by sellers (sellers), i.e., for example: João (sellers) sells to 4 stores (street y, street x, street j, street z) in which each of these stores belongs only to one customer, in this example the shop of street x belongs to the customer Nike, that of street y to the customer Adidas, that of street j belongs also to the Nike and the shop z belongs to the customer Billabong
A store can have more than one seller, e.g.: João sells tennis and Tomás sells coats to the same store.
Relations:
sellers->Stores: many to many (pivot table: stores_sellers)
clients->Stores: one for many
Based on the example above, I wanted a query that would tell me João’s customers through the stores he owns. The result would be: (Nike, Adidas, Billabong)
Post what you’ve tried to do
– Lucio Rubens
I tried with eloquent (Laravel) but I have to go with raw sql since there is no this default relation in Laravel
– Miguel